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

:root {
  --bg-primary: #0a0e27;
  --bg-secondary: #111638;
  --bg-card: #161b40;
  --bg-card-hover: #1c2252;
  --border: rgba(108, 99, 255, 0.15);
  --text-primary: #e8e6ff;
  --text-secondary: #8b87b8;
  --text-muted: #5c5888;
  --accent: #6C63FF;
  --accent-light: #8b83ff;
  --cyan: #00D2FF;
  --green: #00e676;
  --yellow: #ffd740;
  --red: #ff5252;
  --gradient: linear-gradient(135deg, #6C63FF, #00D2FF);
  --shadow: 0 4px 24px rgba(0,0,0,0.3);
  --radius: 16px;
  --radius-sm: 10px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  overflow: hidden;
  height: 100vh;
}

/* ===== Layout ===== */
.app-container {
  display: flex;
  height: 100vh;
}

/* ===== Sidebar ===== */
.sidebar {
  width: 240px;
  min-width: 240px;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 0;
}

.sidebar-header { padding: 0 20px 24px; }

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 18px;
  font-weight: 700;
  color: var(--text-primary);
}

.sidebar-nav {
  flex: 1;
  padding: 0 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.nav-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 14px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  text-align: left;
}

.nav-btn:hover { background: rgba(108,99,255,0.1); color: var(--text-primary); }
.nav-btn.active { background: rgba(108,99,255,0.2); color: var(--accent-light); }

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

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

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
}

.user-info-mini { display: flex; flex-direction: column; }
.user-info-mini span { font-size: 13px; font-weight: 600; }
.user-info-mini small { font-size: 11px; color: var(--text-muted); }

/* ===== Main Content ===== */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ===== Top Bar ===== */
.top-bar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 16px 28px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.top-bar-left { display: flex; align-items: center; gap: 16px; }
.top-bar-left h1 { font-size: 20px; font-weight: 700; }

.live-indicator {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--green);
  background: rgba(0,230,118,0.1);
  padding: 4px 10px;
  border-radius: 20px;
}

.live-dot {
  width: 8px;
  height: 8px;
  background: var(--green);
  border-radius: 50%;
  animation: pulse 1.5s ease-in-out infinite;
}

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

.top-bar-right { display: flex; align-items: center; gap: 16px; }

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

.alert-bell {
  position: relative;
  cursor: pointer;
  color: var(--text-secondary);
  transition: color 0.2s;
}

.alert-bell:hover { color: var(--text-primary); }

.alert-badge {
  position: absolute;
  top: -4px;
  right: -6px;
  background: var(--red);
  color: #fff;
  font-size: 10px;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ===== Alert Panel ===== */
.alert-panel {
  padding: 0 28px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 0;
  overflow: hidden;
  transition: max-height 0.3s, padding 0.3s;
}

.alert-panel.has-alerts { max-height: 200px; padding: 12px 28px; }

.alert-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  animation: slideIn 0.3s ease;
}

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

.alert-item.warning { background: rgba(255,215,64,0.12); border-left: 3px solid var(--yellow); color: var(--yellow); }
.alert-item.danger { background: rgba(255,82,82,0.12); border-left: 3px solid var(--red); color: var(--red); animation: slideIn 0.3s ease, flash 1s ease-in-out infinite; }

@keyframes flash {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

.alert-item.info { background: rgba(0,210,255,0.1); border-left: 3px solid var(--cyan); color: var(--cyan); }

/* ===== View System ===== */
.view { display: none; overflow-y: auto; padding: 24px 28px; flex: 1; }
.view.active { display: block; }

/* ===== Health Score ===== */
.health-score-section {
  display: flex;
  align-items: center;
  gap: 28px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 28px;
  margin-bottom: 20px;
}

.score-ring-container { position: relative; width: 120px; height: 120px; flex-shrink: 0; }

.score-ring { width: 120px; height: 120px; }

.score-text {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.score-value { font-size: 32px; font-weight: 800; background: var(--gradient); -webkit-background-clip: text; -webkit-text-fill-color: transparent; }
.score-text small { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.score-summary { font-size: 14px; color: var(--text-secondary); line-height: 1.6; }

/* ===== Vitals Grid ===== */
.vitals-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.vital-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  position: relative;
  transition: all 0.3s;
  overflow: hidden;
}

.vital-card:hover { background: var(--bg-card-hover); transform: translateY(-2px); }

.vital-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  background: var(--gradient);
}

.vital-card.status-warning::before { background: var(--yellow); }
.vital-card.status-danger::before { background: var(--red); }

.vital-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.vital-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
}

.vital-icon.heart { background: rgba(255,82,82,0.15); }
.vital-icon.bp { background: rgba(108,99,255,0.15); }
.vital-icon.glucose { background: rgba(255,215,64,0.15); }
.vital-icon.spo2 { background: rgba(0,210,255,0.15); }
.vital-icon.temp { background: rgba(255,152,0,0.15); }
.vital-icon.bmi { background: rgba(0,230,118,0.15); }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--green);
}

.status-dot.warning { background: var(--yellow); }
.status-dot.danger { background: var(--red); animation: pulse 1s infinite; }

.vital-value { font-size: 28px; font-weight: 700; margin-bottom: 4px; }
.vital-label { font-size: 12px; color: var(--text-muted); }
.vital-range { font-size: 11px; color: var(--text-muted); margin-top: 6px; }

.vital-value .unit { font-size: 14px; font-weight: 400; color: var(--text-secondary); }

/* ===== Charts ===== */
.charts-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 16px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 14px;
  color: var(--text-secondary);
}

.chart-card canvas { width: 100% !important; height: 220px !important; }

/* ===== Buttons ===== */
.btn-primary {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 20px;
  background: var(--gradient);
  color: #fff;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}

.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 16px rgba(108,99,255,0.4); }

/* ===== Analysis View ===== */
.analysis-container { max-width: 900px; }

.analysis-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.analysis-header h2 { font-size: 20px; }

.analysis-body { min-height: 300px; }

.analysis-loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 300px;
  gap: 16px;
  color: var(--text-secondary);
}

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

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

.analysis-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

.analysis-section h3 {
  font-size: 15px;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.analysis-section p, .analysis-section li {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.8;
}

.analysis-section ul { list-style: none; padding: 0; }
.analysis-section li::before { content: '• '; color: var(--accent); }

.risk-indicator {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
}

.risk-low { background: rgba(0,230,118,0.15); color: var(--green); }
.risk-medium { background: rgba(255,215,64,0.15); color: var(--yellow); }
.risk-high { background: rgba(255,82,82,0.15); color: var(--red); }

/* ===== Plan View ===== */
.plan-container { max-width: 1000px; }

.plan-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}

.plan-header h2 { font-size: 20px; }

.plan-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 16px;
}

.plan-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
}

.plan-card-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}

.plan-card-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  background: rgba(108,99,255,0.12);
}

.plan-card-header h3 { font-size: 15px; }

.plan-card ul { list-style: none; padding: 0; }
.plan-card li {
  font-size: 13px;
  color: var(--text-secondary);
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.04);
  display: flex;
  justify-content: space-between;
}

.plan-card li:last-child { border-bottom: none; }
.plan-card li span { color: var(--text-primary); font-weight: 600; }

.plan-note {
  margin-top: 8px;
  padding: 10px 12px;
  background: rgba(108,99,255,0.08);
  border-radius: var(--radius-sm);
  font-size: 12px;
  color: var(--text-secondary);
  line-height: 1.6;
}

/* ===== Profile View ===== */
.profile-container { max-width: 600px; }
.profile-container h2 { font-size: 20px; margin-bottom: 24px; }

.profile-form {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.form-row {
  display: flex;
  align-items: center;
  gap: 16px;
}

.form-row label {
  width: 100px;
  font-size: 13px;
  color: var(--text-secondary);
  flex-shrink: 0;
}

.form-row input[type="text"],
.form-row input[type="number"],
.form-row select {
  flex: 1;
  padding: 10px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

.form-row input:focus, .form-row select:focus { border-color: var(--accent); }

.form-row select { cursor: pointer; }

.checkbox-group {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  flex: 1;
}

.checkbox-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}

.checkbox-item input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

/* ===== Scrollbar ===== */
.view::-webkit-scrollbar { width: 6px; }
.view::-webkit-scrollbar-track { background: transparent; }
.view::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }

/* ===== Responsive ===== */
@media (max-width: 1024px) {
  .charts-row { grid-template-columns: 1fr; }
  .vitals-grid { grid-template-columns: repeat(3, 1fr); }
}

@media (max-width: 768px) {
  .sidebar { width: 60px; min-width: 60px; padding: 12px 0; }
  .sidebar-header, .sidebar-footer, .nav-btn span { display: none; }
  .nav-btn { justify-content: center; padding: 12px; }
  .vitals-grid { grid-template-columns: repeat(2, 1fr); }
  .charts-row { grid-template-columns: 1fr; }
  .plan-grid { grid-template-columns: 1fr; }
}
