/* =========================================================
   Material 3 Expressive 风格设计系统 (Mobile-First WebApp)
   规范参考: Android Jetpack Compose Material 3 Expressive
   完美手机端响应式布局 · 防撑破溢出 · 触控反馈
   ========================================================= */

:root {
  /* Material 3 Dark 调色板 (Material You 动态基准) */
  --md-sys-color-background: #101318;
  --md-sys-color-on-background: #e0e2e8;
  
  --md-sys-color-surface: #101318;
  --md-sys-color-surface-dim: #101318;
  --md-sys-color-surface-bright: #36393e;
  --md-sys-color-surface-container-lowest: #0b0e13;
  --md-sys-color-surface-container-low: #181c20;
  --md-sys-color-surface-container: #1c2025;
  --md-sys-color-surface-container-high: #272a2f;
  --md-sys-color-surface-container-highest: #31353a;
  
  --md-sys-color-on-surface: #e0e2e8;
  --md-sys-color-on-surface-variant: #c3c6cf;
  --md-sys-color-outline: #8d9199;
  --md-sys-color-outline-variant: #43474e;

  /* 主色调 (Blue / Teal) */
  --md-sys-color-primary: #9ecaff;
  --md-sys-color-on-primary: #003258;
  --md-sys-color-primary-container: #00497d;
  --md-sys-color-on-primary-container: #d1e4ff;

  /* 次要色 (Secondary) */
  --md-sys-color-secondary: #bbc7db;
  --md-sys-color-on-secondary: #253140;
  --md-sys-color-secondary-container: #3c4858;
  --md-sys-color-on-secondary-container: #d7e3f7;

  /* 第三色 (Tertiary / Expressive Flame 热水橙红) */
  --md-sys-color-tertiary: #ffb59d;
  --md-sys-color-on-tertiary: #5d1900;
  --md-sys-color-tertiary-container: #822800;
  --md-sys-color-on-tertiary-container: #ffdbd1;

  /* 状态动态卡片色彩 */
  --state-idle-bg: #1c2025;
  --state-idle-on: #e0e2e8;
  
  --state-active-bg: #5e1900;
  --state-active-on: #ffdbd1;

  --state-settling-bg: #3c234a;
  --state-settling-on: #f7d8ff;

  /* 字体系统 */
  --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Google Sans", "PingFang SC", sans-serif;
  --font-mono: "SF Mono", "JetBrains Mono", "Roboto Mono", Consolas, monospace;
}

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

html, body {
  width: 100%;
  min-height: 100%;
  background-color: var(--md-sys-color-background);
  color: var(--md-sys-color-on-background);
  font-family: var(--font-family);
  line-height: 1.4;
  overflow-x: hidden;
}

body {
  display: flex;
  justify-content: center;
}

/* 移动端主框架容器 */
.app-viewport {
  width: 100%;
  max-width: 440px;
  min-height: 100vh;
  min-height: 100dvh;
  background-color: var(--md-sys-color-background);
  display: flex;
  flex-direction: column;
  position: relative;
  padding-bottom: calc(env(safe-area-inset-bottom, 20px) + 20px);
  overflow-x: hidden;
}

/* 顶部 Large TopAppBar */
.m3-top-app-bar {
  width: 100%;
  padding: 14px 18px 10px 18px;
  display: flex;
  flex-direction: column;
  background: var(--md-sys-color-surface);
  position: sticky;
  top: 0;
  z-index: 50;
}

.top-bar-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
}

.m3-app-title {
  font-size: 1.35rem;
  font-weight: 700;
  letter-spacing: -0.2px;
  color: var(--md-sys-color-on-surface);
}

.m3-icon-button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--md-sys-color-on-surface-variant);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background-color 0.2s;
  flex-shrink: 0;
}

.m3-icon-button:active {
  background-color: var(--md-sys-color-surface-container-high);
}

.m3-icon-button svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

/* 线性进度加载条 */
.m3-linear-progress {
  height: 3px;
  width: 100%;
  background: var(--md-sys-color-surface-container-highest);
  overflow: hidden;
  display: none;
}

.m3-linear-progress.active {
  display: block;
}

.m3-linear-progress::before {
  content: "";
  display: block;
  height: 100%;
  background: var(--md-sys-color-primary);
  animation: m3-indeterminate 1.4s infinite ease-in-out;
}

@keyframes m3-indeterminate {
  0% { transform: translateX(-100%) scaleX(0.2); }
  50% { transform: translateX(30%) scaleX(0.7); }
  100% { transform: translateX(110%) scaleX(0.1); }
}

/* 内容主体滚动区域 */
.app-content {
  width: 100%;
  padding: 8px 16px 20px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

/* 核心状态卡片 (Status Hero) */
.m3-hero-card {
  width: 100%;
  border-radius: 24px;
  padding: 20px 18px;
  background-color: var(--state-idle-bg);
  color: var(--state-idle-on);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-shadow: 0 4px 18px rgba(0, 0, 0, 0.25);
  transition: background-color 0.35s cubic-bezier(0.2, 0, 0, 1),
              color 0.35s cubic-bezier(0.2, 0, 0, 1),
              box-shadow 0.35s ease;
  position: relative;
  overflow: hidden;
}

.m3-hero-card.theme-active {
  background-color: var(--state-active-bg);
  color: var(--state-active-on);
  box-shadow: 0 8px 24px rgba(255, 84, 38, 0.25);
}

.m3-hero-card.theme-settling {
  background-color: var(--state-settling-bg);
  color: var(--state-settling-on);
  box-shadow: 0 8px 22px rgba(184, 90, 230, 0.2);
}

.hero-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.hero-state-title {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  flex: 1;
}

.hero-state-icon {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.12);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.hero-state-icon svg {
  width: 22px;
  height: 22px;
  fill: currentColor;
}

.theme-active .hero-state-icon {
  animation: pulse-icon 1.8s infinite ease-in-out;
}

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

.hero-state-text-wrap {
  min-width: 0;
  flex: 1;
  overflow: hidden;
}

.hero-state-text {
  font-size: 1.25rem;
  font-weight: 700;
  letter-spacing: 0.1px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.hero-substate-text {
  font-size: 0.76rem;
  opacity: 0.75;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 1px;
}

.btn-connect-hero {
  flex-shrink: 0;
  height: 36px;
  padding: 0 14px;
  border-radius: 18px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.1);
  color: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.15s, transform 0.1s;
}

.btn-connect-hero:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.97);
}

/* 计时与主指标 */
.hero-timer-box {
  display: flex;
  flex-direction: column;
  padding: 4px 0;
}

.hero-timer-label {
  font-size: 0.76rem;
  opacity: 0.8;
  font-weight: 500;
}

.hero-timer-value {
  font-size: 2.6rem;
  font-weight: 800;
  letter-spacing: -1px;
  line-height: 1.1;
  margin: 3px 0;
}

/* Assist Chips (2x2 自适应网格) */
.hero-chips-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr);
  gap: 8px;
  width: 100%;
  margin-top: 4px;
}

.m3-chip {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 0.74rem;
  font-weight: 600;
  font-family: var(--font-mono);
  color: inherit;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m3-chip b {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ==========================================
   Material 3 大药丸按钮组 (Pill Action Buttons)
   ========================================== */
.action-buttons-group {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
}

.m3-pill-btn {
  width: 100%;
  height: 70px;
  border-radius: 35px;
  border: none;
  font-size: 1.22rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.2, 0, 0, 1);
  user-select: none;
}

.m3-pill-btn:active:not(:disabled) {
  transform: scale(0.98);
}

.m3-pill-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
  box-shadow: none;
}

.btn-open-water {
  background-color: var(--md-sys-color-tertiary);
  color: var(--md-sys-color-on-tertiary);
  box-shadow: 0 4px 14px rgba(255, 181, 157, 0.25);
}

.btn-open-water svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

.btn-close-water {
  background-color: var(--md-sys-color-surface-container-high);
  color: var(--md-sys-color-on-surface);
  border: 1px solid var(--md-sys-color-outline-variant);
}

.btn-close-water svg {
  width: 24px;
  height: 24px;
  fill: currentColor;
}

/* 次级药丸操作行 (2列网格自适应) */
.sub-actions-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  width: 100%;
}

.m3-sub-action-btn {
  width: 100%;
  height: 48px;
  border-radius: 24px;
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-primary);
  font-size: 0.88rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  cursor: pointer;
  white-space: nowrap;
  transition: background-color 0.2s, transform 0.15s;
}

.m3-sub-action-btn:active:not(:disabled) {
  background: rgba(158, 202, 255, 0.12);
  transform: scale(0.98);
}

.m3-sub-action-btn:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}

.m3-sub-action-btn svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
  flex-shrink: 0;
}

/* ==========================================
   Material 3 容器卡片 (Elevated Cards)
   ========================================== */
.m3-card {
  width: 100%;
  background: var(--md-sys-color-surface-container);
  border-radius: 20px;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.card-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  width: 100%;
}

.card-title span {
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
}

.card-title-btn {
  height: 30px;
  padding: 0 12px;
  border-radius: 15px;
  border: 1px solid var(--md-sys-color-outline);
  background: transparent;
  color: var(--md-sys-color-primary);
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
  white-space: nowrap;
  transition: background-color 0.15s;
}

.card-title-btn:active {
  background: rgba(158, 202, 255, 0.15);
}

/* 双列网格表单 */
.form-grid-2col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 10px;
  width: 100%;
}

.m3-form-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  width: 100%;
  min-width: 0;
}

.m3-form-field label {
  font-size: 0.76rem;
  font-weight: 500;
  color: var(--md-sys-color-on-surface-variant);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.m3-input {
  width: 100%;
  min-width: 0;
  height: 44px;
  background: var(--md-sys-color-surface-container-high);
  border: 1px solid var(--md-sys-color-outline-variant);
  border-radius: 10px;
  padding: 0 12px;
  color: var(--md-sys-color-on-surface);
  font-size: 0.88rem;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.2s;
}

.m3-input:focus {
  border-color: var(--md-sys-color-primary);
}

.m3-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.84rem;
  color: var(--md-sys-color-on-surface);
  cursor: pointer;
  user-select: none;
  margin-top: 2px;
}

.m3-checkbox-label input {
  width: 18px;
  height: 18px;
  accent-color: var(--md-sys-color-primary);
  flex-shrink: 0;
}

/* 终端报文日志卡片 */
.terminal-container {
  width: 100%;
  background: var(--md-sys-color-surface-container-lowest);
  border-radius: 12px;
  padding: 10px;
  max-height: 200px;
  min-height: 100px;
  overflow-y: auto;
  font-family: var(--font-mono);
  font-size: 0.74rem;
  line-height: 1.5;
  border: 1px solid var(--md-sys-color-surface-container-high);
}

.term-line {
  margin-bottom: 2px;
  word-break: break-all;
}

.term-time { color: var(--md-sys-color-outline); }
.term-tx { color: #38bdf8; font-weight: 600; }
.term-rx { color: #4ade80; font-weight: 600; }
.term-success { color: #34d399; }
.term-warn { color: #fbbf24; }
.term-error { color: #f87171; font-weight: 600; }

/* ==========================================
   Material 3 弹窗与提示 (Dialog & Toast)
   ========================================== */
.m3-dialog-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: none;
  align-items: center;
  justify-content: center;
  padding: 20px;
  z-index: 1000;
}

.m3-dialog-overlay.show {
  display: flex;
}

.m3-dialog {
  background: var(--md-sys-color-surface-container-high);
  border-radius: 28px;
  padding: 22px;
  max-width: 340px;
  width: 100%;
  box-shadow: 0 12px 36px rgba(0, 0, 0, 0.5);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.dialog-headline {
  font-size: 1.22rem;
  font-weight: 700;
  color: var(--md-sys-color-on-surface);
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-text {
  font-size: 0.88rem;
  color: var(--md-sys-color-on-surface-variant);
  line-height: 1.5;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

.dialog-btn {
  height: 40px;
  padding: 0 16px;
  border-radius: 20px;
  border: none;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  background: transparent;
  color: var(--md-sys-color-primary);
}

.dialog-btn-confirm {
  background: var(--md-sys-color-tertiary);
  color: var(--md-sys-color-on-tertiary);
}

/* Material 3 浮动提示 (Snackbar / Toast) */
.m3-snackbar {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 20px) + 20px);
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  background: var(--md-sys-color-surface-container-highest);
  color: var(--md-sys-color-on-surface);
  border-radius: 12px;
  padding: 10px 18px;
  font-size: 0.85rem;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.35);
  transition: transform 0.25s cubic-bezier(0.2, 0, 0, 1), opacity 0.25s;
  opacity: 0;
  pointer-events: none;
  z-index: 2000;
  white-space: nowrap;
}

.m3-snackbar.show {
  transform: translateX(-50%) translateY(0);
  opacity: 1;
}

.hidden { display: none !important; }
