/* 商舟智媒 · 手机端
   视觉 token 取自 media-hub app/web/static/ui-v2.css（浅色专业工作台） */
:root {
  --mh-font: "Microsoft YaHei UI", "HarmonyOS Sans SC", "MiSans", "PingFang SC",
             "Noto Sans SC", "Microsoft YaHei", sans-serif;
  --mh-accent: #2F5BF6;
  --mh-accent-hover: #234BD6;
  --mh-accent-soft: #EEF2FF;
  --mh-bg: #F5F6F8;
  --mh-card: #FFFFFF;
  --mh-ink: #161A22;
  --mh-ink-2: #374151;
  --mh-muted: #5B6472;
  --mh-muted-2: #8A92A0;
  --mh-line: #E7E9EF;
  --mh-line-strong: #D9DDE5;
  --mh-radius-s: 8px;
  --mh-radius: 10px;
  --mh-radius-l: 12px;
  --mh-shadow-s: 0 1px 2px rgba(16, 24, 40, .04);
  --mh-shadow: 0 4px 16px rgba(16, 24, 40, .06);
  --mh-shadow-l: 0 12px 32px rgba(16, 24, 40, .10);
  --mh-ok: #16A34A;
  --mh-warn: #D97706;
  --mh-err: #DC2626;
}
@media (prefers-color-scheme: dark) {
  :root {
    --mh-accent: #6E8BFF;
    --mh-accent-hover: #8AA0FF;
    --mh-accent-soft: rgba(110, 139, 255, .16);
    --mh-bg: #080D18;
    --mh-card: #0F1626;
    --mh-ink: #E8ECF4;
    --mh-ink-2: #C7CEDB;
    --mh-muted: #9AA3B5;
    --mh-muted-2: #778094;
    --mh-line: #1C2436;
    --mh-line-strong: #2A3550;
    --mh-shadow-s: 0 1px 2px rgba(0, 0, 0, .4);
    --mh-shadow: 0 4px 16px rgba(0, 0, 0, .35);
    --mh-shadow-l: 0 12px 32px rgba(0, 0, 0, .45);
    --mh-ok: #34D399;
    --mh-warn: #FBBF24;
    --mh-err: #F87171;
  }
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--mh-font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--mh-ink);
  background: var(--mh-bg);
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; -webkit-appearance: none; appearance: none; }
[hidden] { display: none !important; }

/* 视图高度：100vh 回退，dvh 优先；软键盘由 JS 写 --app-h 并用 .has-vvh 覆盖 */
.view { display: flex; flex-direction: column; height: 100vh; }
@supports (height: 100dvh) { .view { height: 100dvh; } }
html.has-vvh .view { height: var(--app-h); }

/* ---------- 登录 ---------- */
.login-view { overflow-y: auto; -webkit-overflow-scrolling: touch; }
.login-wrap {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) calc(20px + env(safe-area-inset-right))
           calc(24px + env(safe-area-inset-bottom)) calc(20px + env(safe-area-inset-left));
}
.login-head { text-align: center; padding-bottom: 22px; }
.brand-mark {
  width: 56px; height: 56px; margin: 0 auto 14px;
  border-radius: 16px;
  background: var(--mh-accent);
  display: flex; align-items: center; justify-content: center;
  box-shadow: var(--mh-shadow);
}
.brand-mark-sm { width: 36px; height: 36px; border-radius: 10px; margin: 0; box-shadow: none; }
.login-head h1 { margin: 0 0 6px; font-size: 24px; line-height: 1.3; letter-spacing: .01em; }
.login-head p { margin: 0; font-size: 14px; color: var(--mh-muted); }
.login-card {
  width: 100%; max-width: 400px;
  background: var(--mh-card);
  border: 1px solid var(--mh-line);
  border-radius: var(--mh-radius-l);
  box-shadow: var(--mh-shadow);
  padding: 18px;
}
.login-foot { margin: 18px 0 0; font-size: 13px; color: var(--mh-muted-2); text-align: center; }
.tabs {
  display: flex; gap: 4px;
  padding: 4px;
  background: var(--mh-bg);
  border-radius: var(--mh-radius);
  margin-bottom: 16px;
}
.tab {
  flex: 1; min-height: 44px;
  border: 0; border-radius: var(--mh-radius-s);
  background: transparent; color: var(--mh-muted);
  font-size: 15px;
}
.tab.is-active { background: var(--mh-card); color: var(--mh-ink); box-shadow: var(--mh-shadow-s); font-weight: 600; }
.form { display: flex; flex-direction: column; gap: 14px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 13px; color: var(--mh-muted); }
.field input {
  width: 100%; min-height: 48px;
  padding: 11px 14px;
  font-size: 16px; /* iOS 聚焦不缩放 */
  color: var(--mh-ink);
  background: var(--mh-card);
  border: 1px solid var(--mh-line-strong);
  border-radius: var(--mh-radius);
  outline: none;
  -webkit-appearance: none; appearance: none;
}
.field input:focus { border-color: var(--mh-accent); box-shadow: 0 0 0 3px var(--mh-accent-soft); }
.field input::placeholder { color: var(--mh-muted-2); }
.btn {
  min-height: 46px; padding: 0 18px;
  border: 1px solid transparent; border-radius: var(--mh-radius);
  font-size: 16px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background-color .15s, opacity .15s;
}
.btn:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--mh-accent); color: #fff; }
.btn-primary:not(:disabled):active { background: var(--mh-accent-hover); }
.btn-ghost { background: transparent; color: var(--mh-accent); border-color: var(--mh-line-strong); }
/* 登录错误提示（类名避开消息行的 .msg，防止样式串味） */
.login-msg { margin: 14px 0 0; padding: 10px 12px; border-radius: var(--mh-radius-s); font-size: 14px; background: rgba(220, 38, 38, .08); color: var(--mh-err); }
.login-msg.is-ok { background: rgba(22, 163, 74, .10); color: var(--mh-ok); }
.boot-fallback { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--mh-bg); }
.boot-card { max-width: 420px; text-align: center; }
.boot-card h1 { font-size: 20px; margin: 0 0 10px; }
.boot-card p { color: var(--mh-muted); font-size: 15px; margin: 0; }

/* ---------- 对话页 ---------- */
.chat-view { background: var(--mh-bg); }
.app-bar {
  flex: none;
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: calc(8px + env(safe-area-inset-top)) calc(12px + env(safe-area-inset-right))
           8px calc(12px + env(safe-area-inset-left));
  background: var(--mh-card);
  border-bottom: 1px solid var(--mh-line);
}
.app-bar-main { display: flex; align-items: center; gap: 10px; min-width: 0; }
.app-bar-text { display: flex; flex-direction: column; min-width: 0; }
.app-bar-text strong { font-size: 16px; line-height: 1.3; }
.machine-label {
  font-size: 12px; color: var(--mh-muted); line-height: 1.3;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 62vw;
}
.icon-btn {
  flex: none; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--mh-muted);
}
.icon-btn:active { background: var(--mh-bg); }

/* 连接状态条 */
.conn-bar {
  flex: none;
  display: flex; align-items: center; gap: 8px;
  min-height: 34px; padding: 6px 14px;
  font-size: 13px; color: var(--mh-muted);
  background: var(--mh-card);
  border-bottom: 1px solid var(--mh-line);
}
.conn-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--mh-muted-2); flex: none; }
.conn-bar[data-state="online"] .conn-dot { background: var(--mh-ok); }
.conn-bar[data-state="reconnect"] .conn-dot { background: var(--mh-warn); animation: pulse 1.2s ease-in-out infinite; }
.conn-bar[data-state="offline"] .conn-dot { background: var(--mh-err); }
.conn-bar[data-state="reconnect"] { color: var(--mh-warn); }
.conn-bar[data-state="offline"] { color: var(--mh-err); }
.conn-retry {
  margin-left: auto; min-height: 28px; padding: 0 10px;
  border: 1px solid currentColor; border-radius: 999px;
  background: transparent; color: inherit; font-size: 12px;
}
.offline-tip {
  margin: 14px; padding: 16px;
  background: var(--mh-card); border: 1px solid var(--mh-line);
  border-radius: var(--mh-radius-l); box-shadow: var(--mh-shadow-s);
  text-align: center;
}
.offline-tip p { margin: 0 0 6px; font-size: 14px; color: var(--mh-muted); }
.offline-tip p strong { color: var(--mh-ink); font-size: 15px; }
.offline-tip .btn { margin-top: 8px; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }

/* 消息流 */
.messages {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto; -webkit-overflow-scrolling: touch;
  overscroll-behavior-y: contain;
  padding: 16px calc(14px + env(safe-area-inset-right)) 16px calc(14px + env(safe-area-inset-left));
}
.msg { display: flex; margin-bottom: 14px; }
.msg-user { justify-content: flex-end; }
.msg-ai { justify-content: flex-start; }
.bubble-user {
  max-width: 84%;
  padding: 10px 14px;
  background: var(--mh-accent); color: #fff;
  border-radius: 16px 16px 4px 16px;
  font-size: 16px; line-height: 1.45;
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}
.task-card {
  width: 100%; max-width: 86%;
  padding: 12px 14px;
  background: var(--mh-card);
  border: 1px solid var(--mh-line);
  border-radius: 4px 16px 16px 16px;
  box-shadow: var(--mh-shadow-s);
}
.task-state { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--mh-muted); }
.task-state strong { color: var(--mh-ink-2); font-weight: 600; }
.spinner {
  width: 14px; height: 14px; flex: none;
  border: 2px solid var(--mh-accent-soft);
  border-top-color: var(--mh-accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.task-progress { margin: 8px 0 0; padding: 0; list-style: none; }
.task-progress li {
  position: relative; padding: 2px 0 2px 16px;
  font-size: 14px; color: var(--mh-muted); line-height: 1.45;
  word-break: break-word;
}
.task-progress li::before {
  content: ""; position: absolute; left: 4px; top: .62em;
  width: 5px; height: 5px; border-radius: 50%; background: var(--mh-line-strong);
}
.result {
  margin-top: 10px; padding-top: 10px;
  border-top: 1px dashed var(--mh-line);
  font-size: 15px; line-height: 1.55; color: var(--mh-ink);
  white-space: pre-wrap; word-break: break-word; overflow-wrap: anywhere;
}
.result.is-failed { color: var(--mh-err); }
.task-meta { margin-top: 8px; font-size: 12px; color: var(--mh-muted-2); }

/* 空态 */
.empty { padding: 32px 8px; text-align: center; }
.empty-title { margin: 0 0 6px; font-size: 17px; font-weight: 600; color: var(--mh-ink); }
.empty-sub { margin: 0 0 18px; font-size: 14px; color: var(--mh-muted); }
.chips { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.chip {
  max-width: 100%; min-height: 44px; padding: 8px 16px;
  background: var(--mh-card); border: 1px solid var(--mh-line-strong);
  border-radius: 999px; color: var(--mh-ink-2); font-size: 14px;
}
.chip:active { background: var(--mh-accent-soft); border-color: var(--mh-accent); }

/* 输入区 */
.composer {
  flex: none;
  padding: 10px calc(12px + env(safe-area-inset-right))
           calc(8px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
  background: var(--mh-card);
  border-top: 1px solid var(--mh-line);
}
.composer-inner { display: flex; align-items: flex-end; gap: 8px; }
.composer-input {
  flex: 1 1 auto; min-height: 44px; max-height: 140px;
  padding: 11px 14px;
  font-size: 16px; /* 防 iOS 聚焦缩放 */
  line-height: 1.45;
  color: var(--mh-ink);
  background: var(--mh-bg);
  border: 1px solid var(--mh-line);
  border-radius: var(--mh-radius-l);
  outline: none;
  resize: none; overflow-y: auto;
  -webkit-appearance: none; appearance: none;
}
.composer-input:focus { border-color: var(--mh-accent); background: var(--mh-card); }
.composer-input::placeholder { color: var(--mh-muted-2); }
.send-btn {
  flex: none; width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: var(--mh-accent); color: #fff;
  transition: background-color .15s, opacity .15s;
}
.send-btn:disabled { opacity: .4; }
.send-btn:not(:disabled):active { background: var(--mh-accent-hover); }
.composer-hint { margin: 6px 4px 0; font-size: 11px; color: var(--mh-muted-2); text-align: center; }

/* ---------- 响应式 ---------- */
@media (max-width: 359px) {
  .login-wrap { padding-left: 14px; padding-right: 14px; }
  .login-card { padding: 14px; }
  .login-head h1 { font-size: 21px; }
  .messages { padding-left: 10px; padding-right: 10px; }
  .bubble-user { max-width: 90%; }
  .task-card { max-width: 94%; }
  .composer { padding-left: 8px; padding-right: 8px; }
  .composer-hint { display: none; }
}
@media (orientation: landscape) and (max-height: 520px) {
  .app-bar { padding-top: calc(4px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .brand-mark-sm { width: 30px; height: 30px; }
  .conn-bar { min-height: 28px; padding-top: 3px; padding-bottom: 3px; }
  .login-head { padding-bottom: 12px; }
  .login-head .brand-mark { width: 44px; height: 44px; margin-bottom: 8px; }
  .login-head p { display: none; }
  .login-wrap { justify-content: flex-start; padding-top: calc(14px + env(safe-area-inset-top)); }
  .composer-hint { display: none; }
  .messages { padding-top: 10px; padding-bottom: 10px; }
}
@media (min-width: 768px) {
  .login-card { max-width: 420px; }
  .chat-view { max-width: 760px; margin: 0 auto; border-left: 1px solid var(--mh-line); border-right: 1px solid var(--mh-line); }
  .bubble-user { max-width: 72%; }
  .task-card { max-width: 76%; }
}
@media (prefers-reduced-motion: reduce) {
  .spinner, .conn-bar[data-state="reconnect"] .conn-dot { animation: none; }
}

/* 轻提示 */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%) translateY(8px);
  max-width: calc(100vw - 40px);
  padding: 10px 16px;
  background: rgba(22, 26, 34, .92);
  color: #fff;
  border-radius: 999px;
  font-size: 14px;
  line-height: 1.4;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
  z-index: 30;
}
.toast.is-show { opacity: 1; transform: translateX(-50%) translateY(0); }
