:root {
  --primary: #2563eb;
  --primary-light: #eff6ff;
  --text-main: #1e293b;
  --text-sub: #64748b;
  --bg-body: #f8fafc;
  --bg-card: #ffffff;
  --border: #e2e8f0;
  --danger: #ef4444;
  --success: #22c55e;
  --warning: #f59e0b;
  --tab-height: 50px;
}

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

body {
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg-body);
  color: var(--text-main);
  font-size: 14px;
  line-height: 1.5;
}

a { text-decoration: none; color: inherit; }

/* 布局容器 */
.m-container {
  padding-bottom: calc(var(--tab-height) + 20px);
  min-height: 100vh;
}

/* 底部导航栏 */
.m-tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: var(--tab-height);
  background: #fff;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: space-around;
  align-items: center;
  z-index: 100;
  padding-bottom: env(safe-area-inset-bottom);
  box-sizing: content-box;
}

.m-tab-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-sub);
  font-size: 10px;
  height: 100%;
}

.m-tab-item.active {
  color: var(--primary);
}

.m-tab-icon {
  font-size: 20px;
  margin-bottom: 2px;
}

.m-tabs {
  display: flex;
  gap: 8px;
  padding: 8px 16px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.m-tab {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  font-size: 13px;
  color: var(--text-sub);
  background: #f8fafc;
  cursor: pointer;
  user-select: none;
}

.m-tab.active {
  color: var(--primary);
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

.m-tab-ico {
  font-size: 16px;
}

/* 登录页样式 */
.m-login-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  min-height: 100dvh;
  min-height: 100svh;
  padding: 30px;
  background: #fff;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  z-index: 200; /* 覆盖 Tabbar */
}

.m-login-logo {
  font-size: 32px;
  font-weight: 800;
  color: var(--primary);
  margin-bottom: 40px;
  letter-spacing: -1px;
}

.m-input-group {
  width: 100%;
  margin-bottom: 20px;
}

.m-input {
  width: 100%;
  height: 28px;
  padding: 2px 16px;
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 16px;
  outline: none;
  background: #f8fafc;
  transition: all 0.2s;
  appearance: none;
}

.m-input:focus {
  border-color: var(--primary);
  background: #fff;
  box-shadow: 0 0 0 3px var(--primary-light);
}

.m-btn {
  width: 100%;
  padding: 8px;
  background: var(--primary);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 400;
  margin-top: 10px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.m-btn.xs {
  width: auto;
  padding: 6px 10px;
  font-size: 12px;
  border-radius: 10px;
  margin-top: 0;
}

.m-btn:active {
  filter: brightness(0.9);
  transform: scale(0.98);
}

/* 通用组件 */
.m-header {
  height: 44px;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  font-size: 17px;
  font-weight: 600;
  position: sticky;
  top: 0;
  z-index: 50;
}

.m-card {
  background: #fff;
  margin: 16px;
  border-radius: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  overflow: hidden;
}

.m-card-header {
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-weight: 600;
  font-size: 15px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

/* 应用网格 */
.m-apps-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 12px;
}

.m-app-icon {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--bg-card);
  border-radius: 16px;
  padding: 0;
  text-decoration: none;
  color: var(--text-main);
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
  transition: transform 0.1s;
  aspect-ratio: 1;
  width: 100%;
}

.m-app-icon:active {
  transform: scale(0.96);
}

.m-app-icon-img {
  font-size: 24px;
  margin-bottom: 4px;
}

.m-app-name {
  font-size: 12px;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  padding: 0 2px;
}

/* 列表内容图片自适应 */
.m-list-sub img {
  max-width: 100% !important;
  height: auto !important;
  border-radius: 4px;
  display: block;
  margin: 4px 0;
}

.m-list {
  background: #fff;
}

.m-list-item {
  padding: 12px 1px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.m-list-item:last-child { border-bottom: none; }

.m-list-title {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-main);
  margin-bottom: 4px;
}
.m-list-sub {
  font-size: 12px;
  color: var(--text-sub);
}
.m-empty {
  padding: 40px;
  text-align: center;
  color: var(--text-sub);
  font-size: 14px;
}

.m-tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 500;
}
.m-tag.success { background: #dcfce7; color: #166534; }
.m-tag.warning { background: #fef3c7; color: #92400e; }
.m-tag.danger { background: #fee2e2; color: #991b1b; }
.m-tag.info { background: #dbeafe; color: #1e40af; }

/* 详情页/个人中心样式 */
.m-field {
  display: flex;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
}
.m-field:last-child {
  border-bottom: none;
}
.m-field-label {
  color: var(--text-sub);
}
.m-field-value {
  color: var(--text-main);
  font-weight: 500;
}
.m-btn-group {
  margin-top: 20px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.m-btn-sm {
  width: 100%;
  padding: 10px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text-main);
  text-align: center;
  cursor: pointer;
}
.m-btn-sm:active {
  background: #f8fafc;
}

/* 聊天容器 */
.m-chat-container {
  display: flex;
  flex-direction: column;
  /* 减去顶部Header、底部Tabbar的高度 */
  height: calc(100vh - 44px - var(--tab-height));
  /* 兼容 iPhone 底部安全区 */
  height: calc(100vh - 44px - var(--tab-height) - env(safe-area-inset-bottom));
  /* 兼容移动端动态视口（修复浏览器导航栏遮挡问题） */
  height: calc(100dvh - 44px - var(--tab-height) - env(safe-area-inset-bottom));
  height: calc(100svh - 44px - var(--tab-height) - env(safe-area-inset-bottom));
  background: #f8fafc;
  position: relative;
}

.m-chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  /* 增加底部内边距，确保最后一条消息不贴底 */
  padding-bottom: 20px;
}

.m-chat-msg {
  display: flex;
  gap: 10px;
  max-width: 85%;
  margin-bottom: 12px;
}

.m-chat-msg.user {
  margin-left: auto;
  align-self: flex-end;
  flex-direction: row-reverse;
}

.m-chat-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}

.m-chat-bubble {
  background: #fff;
  padding: 10px 14px;
  border-radius: 12px;
  border-top-left-radius: 2px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  font-size: 15px;
  line-height: 1.5;
  color: var(--text-main);
  word-break: break-word;
}

.m-chat-msg.user .m-chat-bubble {
  background: var(--primary);
  color: #fff;
  border-radius: 12px;
  border-top-right-radius: 2px;
}

.m-chat-input-bar {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
  background: #fff;
  border-top: 1px solid var(--border);
  /* 确保输入框不被键盘或浏览器UI遮挡 */
  position: sticky;
  bottom: 0;
  z-index: 20;
}

.m-chat-input {
  flex: 1;
  background: #f1f5f9;
  border: none;
  border-radius: 20px;
  padding: 9px 14px;
  font-size: 15px;
  outline: none;
  min-height: 40px;
  max-height: 240px;
  line-height: 1.5;
  resize: none;
}

.m-chat-btn {
  background: transparent;
  border: none;
  color: var(--primary);
  font-size: 24px;
  padding: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.m-chat-btn:disabled {
  color: #cbd5e1;
}

/* 推理过程样式 */
.ab-reasoning {
  font-size: 12px;
  color: #64748b;
  background: #f1f5f9;
  border-left: 2px solid #cbd5e1;
  padding: 8px;
  margin-bottom: 8px;
  border-radius: 4px;
  font-family: monospace;
  white-space: pre-wrap;
}

/* 结构化视图样式 */
.m-struct-view {
  margin-top: 8px;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  padding: 10px;
  font-size: 13px;
}
.m-struct-row {
  display: flex;
  justify-content: space-between;
  padding: 4px 0;
  border-bottom: 1px solid #f1f5f9;
}
.m-struct-row:last-child { border-bottom: none; }
.m-struct-label { color: #64748b; }
.m-struct-val { font-weight: 500; }

/* 浮动操作按钮 (FAB) */
.m-fab {
  position: fixed;
  bottom: 90px;
  right: 20px;
  width: 28px;
  height: 28px;
  background: var(--primary);
  color: #fff;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: bold;
  box-shadow: 0 4px 12px rgba(37, 99, 235, 0.4);
  z-index: 9999;
  cursor: pointer;
  transition: transform 0.2s, box-shadow 0.2s;
}

.m-fab:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(37, 99, 235, 0.4);
}

/* 模态框样式 */
.m-modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  visibility: hidden;
  transition: all 0.3s;
}

.m-modal-overlay.active {
  opacity: 1;
  visibility: visible;
}

.m-modal {
  background: #fff;
  border-radius: 16px;
  width: 90%;
  max-width: 400px;
  padding: 20px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  transform: translateY(20px);
  transition: all 0.3s;
}

.m-modal-overlay.active .m-modal {
  transform: translateY(0);
}

.m-modal-title {
  font-size: 18px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-main);
  text-align: center;
}

.m-modal-body {
  margin-bottom: 20px;
}

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

.m-cmd-list {
  max-height: 200px;
  overflow-y: auto;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
}

.m-cmd-item {
  padding: 10px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.m-cmd-item:last-child {
  border-bottom: none;
}

.m-cmd-item:active {
  background: #f8fafc;
}

.m-cmd-title {
  font-weight: 500;
  font-size: 14px;
}

.m-cmd-code {
  font-size: 12px;
  color: var(--text-sub);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}

.m-chat-btn-text {
  font-size: 14px;
  font-weight: 600;
  margin-left: 4px;
}

.m-chat-btn-plus {
  font-size: 24px;
  width: 30px;
  height: 30px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  border: 1px solid var(--border);
  color: var(--text-sub);
}

.sortable-ghost {
  opacity: 0.4;
  background: #f1f5f9;
  border-radius: 12px;
}

/* 统一按钮主题色 */
.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-danger {
  background: var(--danger);
  color: #fff;
}

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