/**
 * 减肥闸门 V2 - 手机优先的低干扰界面
 * 只负责呈现，不改变配额、同步或通知业务逻辑。
 */

:root {
  color-scheme: light;
  --ink: #17231d;
  --ink-secondary: #405048;
  --muted: #68736d;
  --paper: #f4f5f1;
  --surface: #ffffff;
  --surface-soft: #f8f9f6;
  --line: #e2e6e1;
  --accent: #e99a24;
  --accent-strong: #a85c12;
  --accent-light: #fff6df;
  --primary: #1f684c;
  --primary-strong: #18553e;
  --primary-light: #edf7f1;
  --bad: #b64b3a;
  --bad-light: #fdf0ed;
  --blue-light: #eef5fa;
  --blue: #2c6a8f;
  --free-light: #f8f0f7;
  --free: #8d4e78;
  --shadow: 0 2px 10px rgba(23, 35, 29, 0.05);
  --radius: 16px;
  --nav-height: 64px;
}

* { box-sizing: border-box; }
*[hidden] { display: none !important; }

html { min-height: 100%; background: var(--paper); }

body {
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button, input, textarea, select { font: inherit; }

button {
  -webkit-tap-highlight-color: transparent;
  appearance: none;
  cursor: pointer;
  border: 0;
  border-radius: 12px;
  touch-action: manipulation;
}

button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

.app-shell {
  width: min(100%, 480px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top) + 12px) 16px calc(env(safe-area-inset-bottom) + var(--nav-height) + 24px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.page-content, .quota-dashboard { display: flex; flex-direction: column; gap: 16px; }

.sync-bar {
  min-height: 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 5px 10px;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 10px;
  font-size: 12px;
}

.sync-bar button { width: auto; padding: 4px 6px; color: var(--primary); background: transparent; font-size: 12px; font-weight: 600; }
.sync-dot { width: 7px; height: 7px; display: inline-block; margin-right: 6px; border-radius: 50%; background: #a7b0aa; vertical-align: 1px; }
.sync-dot.synced { background: var(--primary); }
.sync-dot.syncing { background: var(--accent); animation: pulse 1.5s infinite; }
.sync-dot.error { background: var(--bad); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .45; } }

.card { padding: 16px; display: flex; flex-direction: column; gap: 12px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.hero { color: #fff; background: var(--ink); border-color: var(--ink); }
.card.hero h1, .card.hero h2, .card.hero h3, .card.hero .stat-number { color: #fff; }
.card h1, .card h2, .card h3 { margin: 0; color: var(--ink); font-weight: 700; letter-spacing: -0.02em; }
.card h1 { font-size: 24px; line-height: 1.2; }
.card h2 { font-size: 18px; line-height: 1.35; }
.card h3 { font-size: 15px; line-height: 1.4; }
.muted { color: var(--muted); }
.section-heading-row { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }

.dashboard-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.dashboard-title { margin: 0; color: #fff; font-size: 22px; line-height: 1.25; font-weight: 700; }
.dashboard-badge { padding: 3px 8px; color: rgba(255,255,255,.8); background: rgba(255,255,255,.12); border-radius: 999px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.stats-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stat-box { padding: 12px; display: flex; flex-direction: column; gap: 4px; background: rgba(255,255,255,.08); border-radius: 12px; }
.stat-label { color: rgba(255,255,255,.7); font-size: 12px; font-weight: 500; }
.stat-number { color: #fff; font-size: 32px; line-height: 1.1; font-weight: 700; }
.stat-number small { color: rgba(255,255,255,.7) !important; font-size: 13px !important; font-weight: 500; }
.hero-progress-label { margin-bottom: 6px; color: rgba(255,255,255,.7); font-size: 12px; font-weight: 500; }
.meal-grid-14 { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.meal-slot { aspect-ratio: 1; display: grid; place-items: center; color: rgba(255,255,255,.48); background: rgba(255,255,255,.1); border: 1px dashed rgba(255,255,255,.24); border-radius: 6px; font-size: 10px; font-weight: 600; }
.meal-slot.filled { color: #271b08; background: var(--accent); border: 0; }
.meal-slot.filled.free { color: #fff; background: var(--free); }
.meal-slot.filled.over { color: #fff; background: var(--bad); }

.btn-main-order, .btn-primary, .btn-secondary, .btn-ghost, .btn-danger { width: 100%; min-height: 48px; padding: 12px 14px; font-weight: 650; line-height: 1.25; transition: transform .14s ease, background-color .14s ease, border-color .14s ease; }
.btn-main-order:active, .btn-primary:active, .btn-secondary:active, .btn-ghost:active, .btn-danger:active, .brand-card:active { transform: scale(.985); }
.btn-main-order { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; color: #271b08; background: var(--accent); font-size: 18px; font-weight: 700; border-radius: 14px; }
.btn-main-order::after { content: "→"; font-size: 22px; }
.btn-primary { color: #fff; background: var(--primary); }
.btn-primary:hover { background: var(--primary-strong); }
.btn-secondary { color: var(--primary); background: var(--surface); border: 1px solid #b9d4c6; }
.btn-secondary:hover { background: var(--primary-light); }
.btn-ghost { color: var(--ink-secondary); background: var(--surface-soft); border: 1px solid var(--line); }
.btn-danger { color: #fff; background: var(--bad); }
.btn-danger.btn-soft { color: var(--bad); background: var(--bad-light); border: 1px solid #efc5bd; }
button:disabled { cursor: wait; opacity: .55; }

.nav-row { min-height: 40px; display: flex; align-items: center; gap: 10px; }
.btn-back { width: 40px; height: 40px; flex: 0 0 40px; display: grid; place-items: center; color: var(--ink); background: var(--surface); border: 1px solid var(--line); font-size: 24px; line-height: 1; }
.nav-title { min-width: 0; margin: 0; overflow: hidden; color: var(--ink); font-size: 20px; line-height: 1.25; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }

.section-label { margin: 2px 0 -4px; color: var(--ink-secondary); font-size: 13px; line-height: 1.35; font-weight: 700; }
.section-label-sub { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; font-weight: 400; }
.brand-section { display: flex; flex-direction: column; gap: 8px; }
.brand-card { width: 100%; min-height: 64px; padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 12px; color: var(--ink); text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); }
.brand-card.disabled { opacity: .58; background: var(--surface-soft); }
.brand-card-info { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.brand-card-name { overflow: hidden; color: var(--ink); font-size: 16px; font-weight: 650; text-overflow: ellipsis; white-space: nowrap; }
.brand-card-sub { overflow: hidden; color: var(--muted); font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.brand-card-right { display: flex; flex: 0 0 auto; align-items: center; gap: 8px; }
.brand-card-chevron { color: var(--muted); font-size: 20px; line-height: 1; }

.tier-summary-list { display: flex; flex-direction: column; gap: 2px; }
.tier-summary-item { min-height: 56px; padding: 10px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-bottom: 1px solid var(--line); font-size: 13px; }
.tier-summary-item:last-child { border-bottom: 0; }
.tier-summary-copy { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.tier-summary-name { color: var(--ink); font-weight: 650; }
.tier-summary-brands { color: var(--muted); font-size: 12px; }
.tier-summary-status { flex: 0 0 auto; color: var(--primary); font-size: 12px; font-weight: 650; text-align: right; }
.tier-summary-status.is-used { color: var(--muted); }
.text-action-row { display: flex; justify-content: flex-end; }
.text-action { width: auto; min-height: 40px; padding: 8px 10px; color: var(--muted); background: transparent; border-color: transparent; font-size: 12px; }
.setting-row { min-height: 44px; padding: 4px 0; display: flex; align-items: center; justify-content: space-between; gap: 12px; }

.tier-badge { display: inline-flex; align-items: center; min-height: 24px; padding: 3px 8px; border-radius: 999px; font-size: 11px; line-height: 1; font-weight: 650; white-space: nowrap; }
.tier-badge.primary { color: var(--primary); background: var(--primary-light); }
.tier-badge.secondary { color: var(--accent-strong); background: var(--accent-light); }
.tier-badge.supplement { color: var(--blue); background: var(--blue-light); }
.tier-badge.free { color: var(--free); background: var(--free-light); }

.notice-box { padding: 11px 12px; border-radius: 12px; font-size: 13px; line-height: 1.45; font-weight: 550; overflow-wrap: anywhere; }
.notice-box.warn { color: #87580f; background: var(--accent-light); border: 1px solid #f0d895; }
.notice-box.good { color: var(--primary); background: var(--primary-light); border: 1px solid #b9e5c9; }
.notice-box.bad { color: var(--bad); background: var(--bad-light); border: 1px solid #efc5bd; }
.notice-detail { margin-top: 4px; color: inherit; font-size: 12px; font-weight: 400; }

.free-meal-card { gap: 12px; }
.free-meal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.free-meal-name { color: var(--ink); font-size: 16px; font-weight: 650; }
.free-meal-description { margin-top: 2px; color: var(--muted); font-size: 12px; }
.order-box { padding: 14px; display: flex; flex-direction: column; gap: 9px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 14px; }
.order-box-title { color: var(--ink); font-size: 16px; font-weight: 650; }
.order-items-list { margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; list-style: none; }
.order-item-tag { padding: 4px 8px; color: var(--ink-secondary); background: #eaf1ec; border-radius: 7px; font-size: 12px; font-weight: 550; }
.order-box-tip { color: var(--muted); font-size: 12px; line-height: 1.45; }
.rule-list { margin: 0; padding-left: 18px; color: var(--ink-secondary); font-size: 13px; }
.rule-list li { margin-bottom: 6px; }
.rule-heading-danger { margin: 4px 0 0; color: var(--bad); font-size: 15px; }
.sauce-card { background: var(--surface-soft); }

.countdown-panel { padding: 28px 20px; display: flex; flex-direction: column; align-items: center; gap: 8px; color: #fff; text-align: center; background: var(--ink); border-radius: var(--radius); }
.countdown-digits { color: #fff; font-size: 54px; line-height: 1; font-weight: 700; letter-spacing: -.05em; }
.countdown-label { color: rgba(255,255,255,.72); font-size: 13px; font-weight: 500; }
.action-stack { display: flex; flex-direction: column; gap: 10px; }
.drink-prompt { border-left: 4px solid var(--primary); box-shadow: none; }
.drink-prompt h1 { font-size: 22px; }
.drink-prompt p { margin: 0; color: var(--muted); font-size: 15px; }

.form-stack, .form-section { display: flex; flex-direction: column; gap: 12px; }
.form-section { padding-top: 14px; border-top: 1px solid var(--line); }
.form-section-title { color: var(--ink); font-size: 14px; font-weight: 650; }
.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label { color: var(--ink-secondary); font-size: 13px; font-weight: 600; }
.form-group input, .form-group textarea, .form-group select { width: 100%; min-height: 48px; padding: 11px 12px; color: var(--ink); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; font-size: 15px; }
.form-group textarea { min-height: 88px; resize: vertical; }
.form-actions { display: flex; gap: 8px; }
.form-actions > * { flex: 1; }
.checkbox-label { display: flex; align-items: center; gap: 7px; min-height: 28px; color: var(--ink-secondary); font-size: 13px; font-weight: 600; }
.checkbox-label input { width: 18px; height: 18px; accent-color: var(--primary); }
.time-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.time-row { padding: 10px 0; display: flex; flex-direction: column; gap: 7px; }
.time-row + .time-row { padding-left: 10px; border-left: 1px solid var(--line); }
.time-row input { min-height: 44px; }

.history-list { margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; list-style: none; }
.history-item { padding: 11px 12px; background: var(--surface-soft); border: 1px solid var(--line); border-radius: 12px; font-size: 13px; }
.history-item-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; font-weight: 650; }
.history-item-detail { margin-top: 3px; color: var(--muted); font-size: 12px; }
.export-preview { width: 100%; min-height: 100px; margin-top: 2px; padding: 10px; color: var(--ink-secondary); background: var(--surface-soft); border: 1px solid var(--line); border-radius: 10px; font: 11px/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; }
.danger-zone { padding-top: 14px; border-top: 1px solid var(--line); }

.bottom-links { position: fixed; z-index: 10; right: 0; bottom: 0; left: 0; height: calc(var(--nav-height) + env(safe-area-inset-bottom)); padding: 7px 12px env(safe-area-inset-bottom); display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; background: rgba(255,255,255,.96); border-top: 1px solid var(--line); }
.bottom-links button { min-width: 0; min-height: 44px; padding: 7px 4px; overflow: hidden; color: var(--muted); background: transparent; border-radius: 10px; font-size: 12px; font-weight: 600; text-overflow: ellipsis; white-space: nowrap; }
.bottom-links button.is-active { color: var(--primary); background: var(--primary-light); }
.bottom-links button:active { transform: scale(.97); }

@media (min-width: 768px) {
  .bottom-links { right: auto; left: 50%; width: 480px; transform: translateX(-50%); border-right: 1px solid var(--line); border-left: 1px solid var(--line); }
}

@media (max-width: 359px) {
  .app-shell { padding-right: 12px; padding-left: 12px; }
  .time-grid { grid-template-columns: 1fr; }
  .time-row + .time-row { padding-top: 10px; padding-left: 0; border-top: 1px solid var(--line); border-left: 0; }
  .form-actions { flex-direction: column; }
  .stat-number { font-size: 28px; }
  .bottom-links { padding-right: 6px; padding-left: 6px; }
  .bottom-links button { font-size: 11px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
