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

:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'PingFang SC', 'Helvetica Neue', 'Microsoft YaHei', sans-serif;
  background: #1a1a2e;
  color: #eee;
}

.app {
  width: 100%;
  max-width: 600px;
  margin: 0 auto;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: #16213e;
  position: relative;
}

/* ===== Header ===== */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  padding-top: calc(10px + var(--safe-top));
  background: linear-gradient(135deg, #0f3460, #533483);
  flex-shrink: 0;
  z-index: 10;
}

.header-info {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 40px;
  height: 40px;
  background: rgba(255,255,255,0.15);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.header h1 {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.status {
  font-size: 11px;
  color: rgba(255,255,255,0.6);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.header-actions {
  display: flex;
  gap: 0;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
  max-width: 180px;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 18px;
  cursor: pointer;
  padding: 6px;
  border-radius: 10px;
  transition: background 0.2s;
  -webkit-user-select: none;
  user-select: none;
}

.icon-btn:active {
  background: rgba(255,255,255,0.15);
}

/* ===== 通用面板 ===== */
.panel {
  background: #1a1a2e;
  border-bottom: 1px solid rgba(255,255,255,0.1);
  max-height: 60vh;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  animation: slideDown 0.3s ease;
  flex-shrink: 0;
}

@keyframes slideDown {
  from { max-height: 0; opacity: 0; }
  to { max-height: 60vh; opacity: 1; }
}

.panel-header {
  padding: 12px 16px 4px;
}

.panel-header h2 {
  font-size: 15px;
  font-weight: 600;
}

.panel-header p {
  font-size: 12px;
  color: rgba(255,255,255,0.4);
  margin-top: 2px;
}

/* ===== 断食计时器 ===== */
.fasting-ring-wrap {
  position: relative;
  width: 180px;
  height: 180px;
  margin: 12px auto;
}

.fasting-ring {
  width: 100%;
  height: 100%;
}

.fasting-center {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

.fasting-state {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 4px;
}

.fasting-time {
  font-size: 28px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: 1px;
}

.fasting-sub {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
  margin-top: 2px;
}

.fasting-labels {
  display: flex;
  justify-content: center;
  gap: 24px;
  padding: 0 16px 12px;
  font-size: 13px;
}

.fasting-label.eating { color: #4ade80; }
.fasting-label.fasting { color: #f87171; }

/* ===== 体重面板 ===== */
.weight-progress {
  margin-top: 10px;
}

.progress-bar {
  height: 8px;
  background: rgba(255,255,255,0.1);
  border-radius: 4px;
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, #533483, #4ade80);
  border-radius: 4px;
  transition: width 0.5s ease;
  width: 0%;
}

.progress-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: rgba(255,255,255,0.5);
  margin-top: 4px;
}

.weight-stats {
  display: flex;
  justify-content: space-around;
  margin-top: 12px;
}

.stat {
  text-align: center;
}

.stat-val {
  display: block;
  font-size: 22px;
  font-weight: 700;
  color: #e2b0ff;
}

.stat-label {
  font-size: 11px;
  color: rgba(255,255,255,0.4);
}

.weight-input {
  display: flex;
  gap: 8px;
  padding: 10px 16px;
}

.weight-input input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: #eee;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.weight-input input:focus {
  border-color: #533483;
}

.weight-input button {
  padding: 8px 16px;
  background: #533483;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
}

.weight-chart {
  padding: 8px 16px;
}

.chart-svg {
  width: 100%;
  height: 80px;
}

.chart-labels {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: rgba(255,255,255,0.3);
  margin-top: 2px;
}

.weight-history {
  padding: 0 16px 12px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 13px;
}

.h-date { color: rgba(255,255,255,0.4); min-width: 40px; }
.h-weight { font-weight: 600; min-width: 50px; }
.h-diff { min-width: 40px; }
.h-diff .up { color: #f87171; }
.h-diff .down { color: #4ade80; }
.h-note { flex: 1; color: rgba(255,255,255,0.3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.h-del {
  background: none;
  border: none;
  color: rgba(255,255,255,0.2);
  cursor: pointer;
  font-size: 12px;
  padding: 4px;
}
.h-del:hover { color: #f87171; }

/* ===== 饮水面板 ===== */
.water-visual {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 12px 16px;
}

.water-bottle {
  width: 60px;
  height: 120px;
  border: 2px solid rgba(255,255,255,0.2);
  border-radius: 8px 8px 16px 16px;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.water-fill {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: linear-gradient(180deg, #60a5fa, #3b82f6);
  transition: height 0.5s ease;
  height: 0%;
}

.water-amount {
  position: relative;
  z-index: 1;
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,0.5);
}

.water-target {
  font-size: 14px;
  color: rgba(255,255,255,0.5);
}

.water-buttons {
  display: flex;
  gap: 8px;
  padding: 0 16px 8px;
  justify-content: center;
}

.water-buttons button {
  padding: 8px 14px;
  background: rgba(59, 130, 246, 0.2);
  border: 1px solid rgba(59, 130, 246, 0.3);
  color: #60a5fa;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1.3;
  text-align: center;
}

.water-buttons button small {
  font-size: 10px;
  opacity: 0.6;
}

.water-buttons button:active {
  background: rgba(59, 130, 246, 0.4);
}

.water-log {
  padding: 4px 16px 12px;
  max-height: 120px;
  overflow-y: auto;
}

.water-log-item {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: rgba(255,255,255,0.3);
  padding: 3px 0;
}

/* ===== 提醒面板 ===== */
.reminder-list {
  padding: 4px 16px;
}

.reminder-item {
  display: flex;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(255,255,255,0.05);
  font-size: 13px;
  gap: 8px;
}

.reminder-item .r-time {
  color: #e2b0ff;
  font-weight: 600;
  min-width: 46px;
  font-size: 13px;
  flex-shrink: 0;
}

.reminder-item .r-text {
  flex: 1;
  color: rgba(255,255,255,0.7);
  line-height: 1.4;
  min-width: 0;
}

.reminder-item .r-text.past {
  text-decoration: line-through;
  opacity: 0.4;
}

.reminder-item .r-text.next {
  color: #4ade80;
}

.toggle {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
  position: absolute;
}

.toggle .slider {
  position: absolute;
  cursor: pointer;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(255,255,255,0.15);
  border-radius: 22px;
  transition: 0.3s;
}

.toggle .slider:before {
  content: "";
  position: absolute;
  height: 18px;
  width: 18px;
  left: 2px;
  bottom: 2px;
  background: white;
  border-radius: 50%;
  transition: 0.3s;
}

.toggle input:checked + .slider {
  background: #533483;
}

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

.reminder-footer {
  padding: 8px 16px 12px;
}

.reminder-footer button {
  width: 100%;
  padding: 10px;
  background: rgba(83, 52, 131, 0.3);
  border: 1px solid rgba(83, 52, 131, 0.5);
  color: #e2b0ff;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}

.reminder-footer button:active {
  background: rgba(83, 52, 131, 0.6);
}

/* ===== AI配置面板 ===== */
.config-form {
  padding: 8px 16px 16px;
}

.config-form label {
  display: block;
  font-size: 12px;
  color: rgba(255,255,255,0.5);
  margin: 8px 0 4px;
}

.config-form input {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: #eee;
  border-radius: 8px;
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.config-form input:focus {
  border-color: #533483;
}

.config-form button {
  width: 100%;
  margin-top: 12px;
  padding: 10px;
  background: #533483;
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 14px;
  cursor: pointer;
}

.config-form button:active {
  opacity: 0.7;
}

.config-status {
  text-align: center;
  font-size: 13px;
  margin-top: 8px;
  min-height: 20px;
}

/* ===== 提醒弹窗 ===== */
.reminder-toast {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  animation: toastIn 0.4s ease;
}

@keyframes toastIn {
  from { transform: translateY(-100%); }
  to { transform: translateY(0); }
}

.toast-content {
  max-width: 600px;
  margin: 0 auto;
  background: linear-gradient(135deg, #533483, #0f3460);
  padding: 14px 16px;
  padding-top: calc(14px + var(--safe-top));
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: 0 4px 20px rgba(0,0,0,0.4);
}

.toast-text {
  font-size: 14px;
  line-height: 1.5;
  flex: 1;
}

.toast-content button {
  background: rgba(255,255,255,0.2);
  border: none;
  color: white;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 16px;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ===== 聊天区域 ===== */
.chat-container {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.welcome-msg {
  text-align: center;
  padding: 30px 16px;
  color: rgba(255,255,255,0.4);
}

.welcome-msg p { font-size: 15px; }
.welcome-msg .hint { font-size: 13px; margin-top: 8px; }

.message {
  max-width: 88%;
  padding: 10px 14px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.7;
  word-break: break-word;
  animation: fadeIn 0.3s ease;
}

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

.message.user {
  align-self: flex-end;
  background: #533483;
  border-bottom-right-radius: 4px;
}

.message.assistant {
  align-self: flex-start;
  background: #0f3460;
  border-bottom-left-radius: 4px;
}

.message.typing {
  color: rgba(255,255,255,0.5);
  font-style: italic;
}

/* ===== 快捷操作 ===== */
.quick-actions {
  display: flex;
  gap: 8px;
  padding: 8px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  flex-shrink: 0;
  scrollbar-width: none;
}

.quick-actions::-webkit-scrollbar { display: none; }

.quick-actions button {
  flex-shrink: 0;
  padding: 8px 14px;
  border: 1px solid rgba(255,255,255,0.15);
  background: rgba(255,255,255,0.05);
  color: #ccc;
  border-radius: 20px;
  font-size: 13px;
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
  -webkit-user-select: none;
  user-select: none;
}

.quick-actions button:active {
  background: rgba(255,255,255,0.15);
  color: #fff;
}

/* ===== 输入区域 ===== */
.input-area {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  padding-bottom: calc(10px + var(--safe-bottom));
  background: #1a1a2e;
  flex-shrink: 0;
}

.input-area input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid rgba(255,255,255,0.1);
  background: rgba(255,255,255,0.05);
  color: #eee;
  border-radius: 24px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  -webkit-appearance: none;
  appearance: none;
}

.input-area input:focus { border-color: #533483; }

.input-area button {
  padding: 12px 20px;
  background: linear-gradient(135deg, #533483, #0f3460);
  color: #fff;
  border: none;
  border-radius: 24px;
  font-size: 15px;
  cursor: pointer;
  transition: opacity 0.2s;
  flex-shrink: 0;
  -webkit-user-select: none;
  user-select: none;
}

.input-area button:active { opacity: 0.7; }
.input-area button:disabled { opacity: 0.4; }

/* ===== 滚动条 ===== */
.chat-container::-webkit-scrollbar { width: 3px; }
.chat-container::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}

/* ===== Markdown ===== */
.message ul, .message ol { padding-left: 18px; margin: 6px 0; }
.message p { margin: 4px 0; }
.message strong { color: #e2b0ff; }

/* ===== 移动端适配 ===== */
@media (max-width: 480px) {
  .app { max-width: 100%; }
  .header h1 { font-size: 14px; }
  .message { max-width: 92%; font-size: 14px; padding: 9px 12px; }
  .quick-actions button { font-size: 12px; padding: 7px 12px; }
}

@media (max-height: 400px) and (orientation: landscape) {
  .quick-actions { display: none; }
  .chat-container { padding: 8px; }
  .header { padding: 6px 12px; }
}
