/* 全局样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* 农业主题绿色系 */
    --primary-color: #4CAF50;
    --secondary-color: #45a049;
    --accent-color: #8BC34A;
    --dark-green: #2E7D32;
    --light-green: #C8E6C9;
    
    /* 功能性颜色 */
    --danger-color: #e74c3c;
    --warning-color: #FF9800;
    --info-color: #2196F3;
    --success-color: #66BB6A;
    
    /* 基础颜色 */
    --dark-color: #1B5E20;
    --light-color: #F1F8E9;
    --white: #ffffff;
    --border-radius: 12px;
    --shadow: 0 4px 6px rgba(46, 125, 50, 0.1);
    --shadow-lg: 0 10px 30px rgba(46, 125, 50, 0.15);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    /* 农业主题绿色渐变背景 */
    background: linear-gradient(135deg, #66BB6A 0%, #4CAF50 50%, #2E7D32 100%);
    min-height: 100vh;
    color: var(--dark-color);
}

/* 导航栏 */
.navbar {
    background: var(--white);
    box-shadow: var(--shadow);
    position: sticky;
    top: 0;
    z-index: 1000;
}

.navbar .container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 1rem 2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.nav-brand {
    display: flex;
    align-items: center;
    gap: 1rem;
    color: var(--primary-color);
}

.nav-brand i {
    font-size: 2rem;
}

.nav-brand h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.nav-menu {
    display: flex;
    gap: 1rem;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    text-decoration: none;
    color: var(--dark-color);
    border-radius: var(--border-radius);
    transition: all 0.3s ease;
    font-weight: 500;
}

.nav-item:hover {
    background: var(--light-color);
    color: var(--primary-color);
}

.nav-item.active {
    background: var(--primary-color);
    color: var(--white);
}

/* 主内容区 */
.main-content {
    max-width: 1400px;
    margin: 2rem auto;
    padding: 0 2rem;
}

.page {
    display: none;
}

.page.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

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

.container {
    width: 100%;
}

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 2rem;
    color: var(--white);
}

.page-header h2 {
    font-size: 2rem;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.info-badge {
    background: rgba(255, 255, 255, 0.2);
    backdrop-filter: blur(10px);
    color: var(--white);
    padding: 0.75rem 1.5rem;
    border-radius: 25px;
    font-size: 0.9rem;
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    border: 1px solid rgba(255, 255, 255, 0.3);
}

/* 卡片样式 */
.card {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    margin-bottom: 2rem;
    overflow: hidden;
}

.card-header {
    padding: 1.5rem;
    border-bottom: 2px solid var(--light-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.card-content {
    padding: 1.5rem;
}

/* 传感器卡片网格 */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.sensor-card {
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.sensor-card:hover {
    transform: translateY(-5px);
    box-shadow: var(--shadow-lg);
}

.card-icon {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    color: var(--white);
}

.card-icon.temperature {
    background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
}

.card-icon.humidity {
    background: linear-gradient(135deg, #4facfe 0%, #00f2fe 100%);
}

.card-icon.light {
    background: linear-gradient(135deg, #fa709a 0%, #fee140 100%);
}

.card-icon.soil {
    background: linear-gradient(135deg, #30cfd0 0%, #330867 100%);
}

.sensor-card .card-content {
    padding: 0;
    flex: 1;
}

.sensor-card h3 {
    font-size: 0.9rem;
    color: #7f8c8d;
    margin-bottom: 0.5rem;
    font-weight: 500;
}

.sensor-card .value {
    font-size: 2.5rem;
    font-weight: 700;
    color: var(--dark-color);
    line-height: 1;
}

.sensor-card .unit {
    font-size: 1rem;
    color: #95a5a6;
    margin-top: 0.25rem;
}

/* 图表容器 */
.chart-container {
    padding: 1.5rem;
    position: relative;
}

.chart-card {
    margin-bottom: 2rem;
}

/* 设备状态概览 */
.devices-overview {
    padding: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 1rem;
}

.device-status-item {
    padding: 1rem;
    background: var(--light-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 1rem;
}

.device-status-item i {
    font-size: 1.5rem;
}

.device-status-item.online {
    background: #d4edda;
    color: #155724;
}

.device-status-item.offline {
    background: #f8d7da;
    color: #721c24;
}

.device-status-item.fault {
    background: #fff3cd;
    color: #856404;
}

/* 按钮样式 */
.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    cursor: pointer;
    font-size: 1rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    transition: all 0.3s ease;
    text-decoration: none;
}

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

.btn-primary:hover {
    background: var(--secondary-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

.btn-secondary {
    background: #95a5a6;
    color: var(--white);
}

.btn-secondary:hover {
    background: #7f8c8d;
}

.btn-info {
    background: var(--info-color);
    color: var(--white);
}

.btn-info:hover {
    background: #1976D2;
}

.btn-success {
    background: var(--success-color);
    color: var(--white);
}

.btn-success:hover {
    background: #4CAF50;
}

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

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

.btn-sm {
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
}

/* 表单样式 */
.search-card {
    margin-bottom: 2rem;
}

.search-form {
    padding: 1.5rem;
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

/* 检索模式切换 */
.search-mode-toggle {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.mode-btn {
    flex: 1;
    padding: 1rem 1.5rem;
    border: 2px solid var(--light-green);
    background: var(--white);
    color: var(--dark-green);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.mode-btn:hover {
    background: var(--light-green);
    transform: translateY(-2px);
}

.mode-btn.active {
    background: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

.mode-description {
    padding: 1rem;
    background: var(--light-green);
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
    color: var(--dark-green);
    line-height: 1.6;
    margin: 0;
}

.mode-description i {
    color: var(--primary-color);
    margin-right: 0.5rem;
}

.mode-description strong {
    color: var(--dark-green);
    font-weight: 700;
}

/* 算法切换 */
.algorithm-toggle {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
}

.algo-btn {
    flex: 1;
    padding: 1rem 1.5rem;
    border: 2px solid var(--light-green);
    background: var(--white);
    color: var(--dark-green);
    border-radius: var(--border-radius);
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
}

.algo-btn:hover {
    background: var(--light-green);
    transform: translateY(-2px);
}

.algo-btn.active {
    background: var(--primary-color);
    color: var(--white);
    border-color: var(--primary-color);
}

.algo-description {
    padding: 1rem;
    background: var(--light-green);
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
    color: var(--dark-green);
    line-height: 1.6;
    margin: 0;
}

.algo-description i {
    color: var(--primary-color);
    margin-right: 0.5rem;
}

.algo-description strong {
    color: var(--dark-green);
    font-weight: 700;
}

/* 搜索进度条 */
.search-progress {
    padding: 1rem 1.5rem;
    background: var(--light-green);
    border-top: 2px solid var(--light-color);
}

.progress-info {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
    color: var(--dark-green);
    font-weight: 600;
}

.progress-bar {
    width: 100%;
    height: 30px;
    background: var(--white);
    border-radius: 15px;
    overflow: hidden;
    box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.1);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-color) 0%, var(--primary-color) 100%);
    border-radius: 15px;
    transition: width 0.1s ease;
    display: flex;
    align-items: center;
    justify-content: flex-end;
    padding-right: 10px;
    color: var(--white);
    font-weight: 600;
    font-size: 0.85rem;
}

.form-group {
    flex: 1;
    min-width: 200px;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-weight: 500;
    color: var(--dark-color);
}

.form-control {
    width: 100%;
    padding: 0.75rem;
    border: 2px solid var(--light-color);
    border-radius: 8px;
    font-size: 1rem;
    transition: border-color 0.3s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary-color);
}

/* 表格样式 */
.table-container {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

thead {
    background: var(--light-color);
}

th, td {
    padding: 1rem;
    text-align: left;
    border-bottom: 1px solid var(--light-color);
}

th {
    font-weight: 600;
    color: var(--dark-color);
}

tbody tr:hover {
    background: #f8f9fa;
}

.text-center {
    text-align: center !important;
}

/* 徽章 */
.badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.875rem;
    font-weight: 600;
    background: var(--primary-color);
    color: var(--white);
}

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

.badge.warning {
    background: var(--warning-color);
}

.badge.info {
    background: var(--info-color);
}

/* 状态标签 */
.status-badge {
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.75rem;
    font-weight: 600;
    display: inline-block;
}

.status-online {
    background: #d4edda;
    color: #155724;
}

.status-offline {
    background: #f8d7da;
    color: #721c24;
}

.status-fault {
    background: #fff3cd;
    color: #856404;
}

.status-unhandled {
    background: #f8d7da;
    color: #721c24;
}

.status-processing {
    background: #fff3cd;
    color: #856404;
}

.status-handled {
    background: #d4edda;
    color: #155724;
}

/* 统计卡片 */
.stats-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 1.5rem;
    margin-bottom: 2rem;
}

.stat-card {
    background: var(--white);
    border-radius: var(--border-radius);
    box-shadow: var(--shadow);
    padding: 1.5rem;
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.stat-icon {
    width: 60px;
    height: 60px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    color: var(--white);
}

.stat-card.danger .stat-icon {
    background: var(--danger-color);
}

.stat-card.warning .stat-icon {
    background: var(--warning-color);
}

.stat-card.info .stat-icon {
    background: var(--info-color);
}

.stat-label {
    font-size: 0.9rem;
    color: #7f8c8d;
    margin-bottom: 0.5rem;
}

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

/* 二分查找可视化 */
.description {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
    padding: 1rem;
    background: #e3f2fd;
    border-radius: 8px;
    color: #1565c0;
    line-height: 1.6;
}

.description i {
    font-size: 1.5rem;
    margin-top: 0.25rem;
}

.algorithm-steps {
    padding: 1.5rem;
    min-height: 200px;
}

.step-info {
    padding: 1rem;
    background: var(--light-color);
    border-radius: 8px;
    text-align: center;
    color: #7f8c8d;
}

.step-item {
    padding: 1rem;
    margin-bottom: 1rem;
    background: #f8f9fa;
    border-left: 4px solid var(--primary-color);
    border-radius: 4px;
    animation: slideIn 0.3s ease;
}

@keyframes slideIn {
    from { opacity: 0; transform: translateX(-20px); }
    to { opacity: 1; transform: translateX(0); }
}

.step-item.active {
    background: #d4edda;
    border-left-color: var(--primary-color);
}

.step-item.found {
    background: #d4edda;
    border-left-color: var(--primary-color);
    font-weight: 600;
}

.step-number {
    display: inline-block;
    width: 30px;
    height: 30px;
    background: var(--primary-color);
    color: var(--white);
    border-radius: 50%;
    text-align: center;
    line-height: 30px;
    font-weight: 600;
    margin-right: 1rem;
}

/* 二分查找可视化数组 */
.binary-visualization {
    padding: 1.5rem;
    overflow-x: auto;
}

.data-array {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 0.5rem;
    padding: 1rem;
}

.data-item {
    min-width: 100px;
    padding: 0.75rem;
    background: var(--light-color);
    border: 2px solid transparent;
    border-radius: 8px;
    text-align: center;
    transition: all 0.3s ease;
}

.data-item.checking {
    background: #fff3cd;
    border-color: var(--warning-color);
    transform: scale(1.05);
}

.data-item.found {
    background: #d4edda;
    border-color: var(--primary-color);
    transform: scale(1.1);
    box-shadow: 0 0 20px rgba(46, 204, 113, 0.3);
}

.data-item.excluded {
    opacity: 0.3;
    background: #e9ecef;
}

.data-item.in-range {
    background: #e3f2fd;
    border-color: var(--info-color);
}

.data-item .time {
    font-size: 0.75rem;
    color: #7f8c8d;
    margin-bottom: 0.25rem;
}

.data-item .value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--dark-color);
}

.data-item .label {
    font-size: 0.7rem;
    color: var(--primary-color);
    font-weight: 600;
    margin-top: 0.25rem;
}

.data-item .humidity {
    font-size: 0.75rem;
    color: #7f8c8d;
    margin-top: 0.25rem;
}

.data-item .index-label {
    font-size: 0.7rem;
    color: #95a5a6;
    margin-top: 0.25rem;
}

.data-item .highlight-label {
    position: absolute;
    top: -10px;
    right: -10px;
    background: var(--primary-color);
    color: white;
    padding: 0.25rem 0.5rem;
    border-radius: 12px;
    font-size: 0.7rem;
    font-weight: 600;
    box-shadow: 0 2px 4px rgba(0,0,0,0.2);
    animation: pulse 1s infinite;
}

.data-item {
    position: relative;
}

@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}

/* 结果显示 */
.result-display {
    padding: 1.5rem;
}

.result-success {
    background: linear-gradient(135deg, #d4edda 0%, #c3e6cb 100%);
    border-left: 4px solid var(--success-color);
    padding: 1.5rem;
    border-radius: 8px;
}

.result-warning {
    background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
    border-left: 4px solid var(--warning-color);
    padding: 1.5rem;
    border-radius: 8px;
}

.result-title {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    color: var(--dark-color);
}

.result-title i {
    font-size: 1.5rem;
}

.result-success {
    padding: 1.5rem;
    background: #d4edda;
    border-left: 4px solid var(--primary-color);
    border-radius: 8px;
}

.result-not-found {
    padding: 1.5rem;
    background: #f8d7da;
    border-left: 4px solid var(--danger-color);
    border-radius: 8px;
}

.result-title {
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.result-info {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.result-item {
    display: flex;
    flex-direction: column;
}

.result-label {
    font-size: 0.875rem;
    color: #7f8c8d;
    margin-bottom: 0.25rem;
}

.result-value {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--dark-color);
}

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    animation: fadeIn 0.3s ease;
}

.modal.active {
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--white);
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 500px;
    box-shadow: var(--shadow-lg);
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from { opacity: 0; transform: translateY(-50px); }
    to { opacity: 1; transform: translateY(0); }
}

.modal-header {
    padding: 1.5rem;
    border-bottom: 2px solid var(--light-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h3 {
    font-size: 1.25rem;
    font-weight: 600;
}

.close {
    font-size: 2rem;
    font-weight: 300;
    color: #7f8c8d;
    cursor: pointer;
    transition: color 0.3s ease;
}

.close:hover {
    color: var(--dark-color);
}

.modal-body {
    padding: 1.5rem;
}

.modal-footer {
    padding: 1.5rem;
    border-top: 2px solid var(--light-color);
    display: flex;
    justify-content: flex-end;
    gap: 1rem;
}

/* 加载状态 */
.loading {
    text-align: center;
    padding: 2rem;
    color: #7f8c8d;
    font-size: 1.1rem;
}

/* 算法演示页面左右布局 */
.algorithm-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 1.5rem;
    margin-top: 1.5rem;
}

.algorithm-left {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.algorithm-right {
    position: sticky;
    top: 80px;
    height: fit-content;
    max-height: calc(100vh - 100px);
}

.algorithm-steps-card {
    height: 100%;
    display: flex;
    flex-direction: column;
}

.algorithm-steps-card .card-header {
    flex-shrink: 0;
}

.algorithm-steps {
    flex: 1;
    overflow-y: auto;
    min-height: 600px;
    max-height: calc(100vh - 200px);
    height: 600px;
}

.algorithm-steps::-webkit-scrollbar {
    width: 8px;
}

.algorithm-steps::-webkit-scrollbar-track {
    background: var(--light-color);
    border-radius: 4px;
}

.algorithm-steps::-webkit-scrollbar-thumb {
    background: var(--primary-color);
    border-radius: 4px;
}

.algorithm-steps::-webkit-scrollbar-thumb:hover {
    background: var(--secondary-color);
}

/* 响应式设计 */
@media (max-width: 1200px) {
    .algorithm-layout {
        grid-template-columns: 1fr 350px;
    }
}

@media (max-width: 968px) {
    .algorithm-layout {
        grid-template-columns: 1fr;
    }
    
    .algorithm-right {
        position: static;
        max-height: none;
    }
    
    .algorithm-steps {
        max-height: 500px;
    }
    
    .data-array {
        grid-template-columns: repeat(4, 1fr);
    }
}

@media (max-width: 600px) {
    .data-array {
        grid-template-columns: repeat(3, 1fr);
    }
}

@media (max-width: 768px) {
    .navbar .container {
        flex-direction: column;
        gap: 1rem;
    }

    .nav-menu {
        flex-wrap: wrap;
        justify-content: center;
    }

    .nav-item span {
        display: none;
    }

    .page-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .cards-grid {
        grid-template-columns: 1fr;
    }

    .search-form {
        flex-direction: column;
    }

    .form-group {
        width: 100%;
    }
}
