/* ============================================================================
 *  凉山惠乔生物科技 · 手机端 AI 入口（PWA）—— 样式
 *  说明：移动端优先，处理刘海屏 / 状态栏 / 底部横条（安全区），
 *        并覆盖启动页、iframe 全屏、离线页、未配置页、安装引导等所有界面。
 * ==========================================================================*/

/* ---------- 主题变量（app.js 会按 config.js 覆盖 --theme / --bg） ---------- */
:root {
  /* 默认值与 config.js 的 themeColor 保持一致（OceanToken 品牌蓝）：
     offline.html 不加载 config.js，靠这里的默认值取色。 */
  --theme: #0C6E93;
  --bg: #FFFFFF;
  --text: #1F2933;
  --text-weak: #6B7280;
  --border: #E5E7EB;
  --card-bg: #FFFFFF;
  --mask: rgba(17, 24, 39, 0.55);
}

/* ---------- 基础重置 ---------- */
* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

/* HTML 的 hidden 属性必须最强优先级：
   下面 .screen / .toast 等用了 display:flex，会覆盖浏览器默认的 [hidden]{display:none}，
   导致带 hidden 的界面在首屏一闪而过。 */
[hidden] {
  display: none !important;
}

html {
  height: 100%;
  background: var(--theme); /* 状态栏区域（安全区）填充主题色 */
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
               "Microsoft YaHei", "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  overscroll-behavior-y: none;
  /* 安全区：刘海屏顶部、底部横条 */
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* 以「已安装的 App」方式运行时，顶部不再需要浏览器的额外留白 */
body.standalone {
  user-select: none;
  -webkit-user-select: none;
}

/* ---------- 全屏视图容器 ---------- */
.screen {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 24px;
  padding-top: calc(24px + env(safe-area-inset-top));
  padding-bottom: calc(24px + env(safe-area-inset-bottom));
  background: var(--bg);
  z-index: 10;
  text-align: center;
}

/* ---------- 启动页品牌标志（OceanToken 标志，图片而非文字） ---------- */
.boot-logo {
  /* 尺寸与圆角跟图标本体一致：标志 svg 的圆角是 54/240 = 22.5%，
     72px 对应 16px（不能再是原来的 18px，会与图形自带的圆角对不齐）。 */
  width: 72px;
  height: 72px;
  border-radius: 16px;
  display: block;
  object-fit: contain;
  /* 图形自带渐变 + 内高光，阴影调淡，避免和图案本身的光晕叠加后发脏 */
  box-shadow: 0 6px 16px rgba(10, 53, 80, 0.18);
  margin-bottom: 22px;
}

.spinner {
  width: 30px;
  height: 30px;
  border: 3px solid rgba(0, 0, 0, 0.08);
  border-top-color: var(--theme);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* 跳转过渡页上的应用名（如「惠乔oceanAI」），让用户看出这是主动跳转而非闪退 */
.boot-sub {
  margin: 0 0 10px;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

/* 启动页标语（config.js 的 bootSlogan）：比应用名小一号、颜色淡一些。
   没填时 app.js 会给元素加 hidden，整行不占位。 */
.boot-slogan {
  margin: 0 0 18px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-weak);
  letter-spacing: 1px;
}

.boot-text {
  margin: 16px 0 0;
  font-size: 15px;
  color: var(--text-weak);
}

/* ---------- AI 平台 iframe（全屏） ---------- */
#ai-frame {
  position: fixed;
  left: 0;
  right: 0;
  top: env(safe-area-inset-top);
  bottom: env(safe-area-inset-bottom);
  width: 100%;
  /* ★ 必须显式给 height：iframe 是替换元素，height:auto 会取内在高度 150px
       （实测 390x844 视口下只有 150px，平台内容只占顶部一条）。
       下面给三档：纯百分比兜底 → vh 精确值 → dvh（iOS 动态工具栏更准）。
       写了 height 之后 bottom 会因过约束被忽略，这正是我们要的：
       实际高度 = 100vh - 顶部安全区 - 底部安全区。 */
  height: 100%;
  height: calc(100vh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  height: calc(100dvh - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  border: 0;
  background: var(--bg);
  z-index: 1;
  display: none;
}

/* 注意：必须写成「#ai-frame.xxx」的形式，
   否则 #ai-frame 这条 ID 选择器优先级更高，会压掉 .ai-frame-visible，iframe 永远显示不出来 */
#ai-frame.ai-frame-visible {
  display: block;
}

/* ---------- 卡片（离线页 / 未配置页） ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 26px 20px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.06);
}

.card-wide {
  max-width: 520px;
  text-align: left;
}

.card-icon {
  font-size: 40px;
  line-height: 1;
  margin-bottom: 12px;
}

.card h2 {
  margin: 0 0 10px;
  font-size: 19px;
}

.card p {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-weak);
}

/* ---------- 进入闸门页（复用 .card / .boot-logo / .btn，仅补几处排版） ---------- */
/* .screen 是 flex 居中的，但 .card 内部不是；这里把品牌标志居中 */
.gate-logo {
  margin: 0 auto 18px;
}

/* 闸门页里的应用名（比启动页略大，作为卡片主标题） */
.gate-app-name {
  margin: 0 0 8px;
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: 0.5px;
}

/* 闸门页标语（config.js 的 bootSlogan）：没填时 app.js 会加 hidden，整行不占位。
   用 .card .gate-slogan 提高优先级，避免被 .card p 的同名属性覆盖 */
.card .gate-slogan {
  margin: 0 0 18px;
  font-size: 14px;
  font-weight: 400;
  color: var(--text-weak);
  letter-spacing: 1px;
}

/* 闸门页说明文案（同样提高优先级，避免被 .card p 覆盖） */
.card .gate-body {
  margin: 0 0 20px;
  font-size: 14px;
  line-height: 1.7;
  color: var(--text-weak);
}

/* 闸门页底部的企业名（class="guide-company"）。
   必须写 .card .guide-company 而不是只靠 .guide-company ——
   .card p(0,1,1) 的优先级高于 .guide-company(0,1,0)，
   不提权的话企业名会变成 14px、margin-top 归零（紧贴按钮、比别处大一号）。
   注：这个坑只有真实浏览器渲染才看得出来，纯逻辑测试（无 CSS 引擎）永远发现不了。 */
.card .guide-company {
  /* 用 margin 简写把 .card p 的 margin:0 0 18px 一并盖掉，否则底部会多出 18px 空隙 */
  margin: 16px 0 0;
  font-size: 12px;
  line-height: 1.6;
}

/* ---------- 按钮 ---------- */
.btn {
  appearance: none;
  border: 0;
  border-radius: 10px;
  font-size: 15px;
  padding: 12px 20px;
  cursor: pointer;
  font-family: inherit;
}

.btn-primary {
  background: var(--theme);
  color: #fff;
  font-weight: 600;
  width: 100%;
}

.btn-primary:active {
  opacity: 0.85;
}

.btn-sm {
  width: auto;
  padding: 9px 14px;
  font-size: 14px;
}

.btn-text {
  background: transparent;
  color: var(--text-weak);
  padding: 9px 8px;
  font-size: 14px;
}

/* ---------- 未配置页清单 ---------- */
.nc-list {
  margin: 0 0 16px;
  padding-left: 18px;
}

.nc-list li {
  margin-bottom: 14px;
  font-size: 14px;
  line-height: 1.6;
}

.nc-item-title {
  font-weight: 700;
  color: #B45309;
}

.nc-item-value {
  color: var(--text-weak);
  word-break: break-all;
}

.nc-item-how {
  color: #374151;
}

.nc-foot {
  margin: 0;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
  font-size: 13px;
  line-height: 1.8;
  color: var(--text-weak);
}

.nc-foot code {
  background: #F3F4F6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 13px;
}

/* ---------- 顶部提示条 ---------- */
.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  top: calc(10px + env(safe-area-inset-top));
  z-index: 60;
  background: rgba(17, 24, 39, 0.92);
  color: #fff;
  font-size: 14px;
  line-height: 1.5;
  padding: 12px 14px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 10px;
  opacity: 0;
  transform: translateY(-12px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.toast.toast-show {
  opacity: 1;
  transform: translateY(0);
}

.toast span {
  flex: 1;
}

.toast-action {
  appearance: none;
  border: 0;
  background: #fff;
  color: #111827;
  font-weight: 600;
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}

/* ---------- Android 安装引导条 ---------- */
.install-bar {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  z-index: 50;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.14);
  opacity: 0;
  transform: translateY(16px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.install-bar.install-bar-show {
  opacity: 1;
  transform: translateY(0);
}

.install-bar-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 10px;
  font-size: 13px;
  color: var(--text-weak);
}

.install-bar-text strong {
  font-size: 15px;
  color: var(--text);
}

.install-bar-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 6px;
}

/* ---------- iOS 安装引导浮层 ---------- */
.ios-guide {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: none;
}

/* 同理，用 ID + class 组合，避免被 #ios-guide 的 display:none 压掉 */
#ios-guide.ios-guide-show {
  display: block;
}

.ios-guide-mask {
  position: absolute;
  inset: 0;
  background: var(--mask);
}

.ios-guide-panel {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(12px + env(safe-area-inset-bottom));
  background: #fff;
  border-radius: 18px;
  padding: 22px 18px;
  max-height: 86vh;
  overflow-y: auto;
  text-align: left;
}

.ios-guide-close {
  position: absolute;
  top: 8px;
  right: 12px;
  appearance: none;
  border: 0;
  background: transparent;
  font-size: 26px;
  line-height: 1;
  color: var(--text-weak);
  cursor: pointer;
}

.ios-guide-panel h3 {
  margin: 0 0 6px;
  font-size: 18px;
}

.ios-guide-sub {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-weak);
}

.ios-steps {
  list-style: none;
  margin: 0 0 16px;
  padding: 0;
}

.ios-steps li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 0;
  border-top: 1px solid var(--border);
  font-size: 14px;
  line-height: 1.6;
}

.ios-steps li:first-child {
  border-top: 0;
}

.step-no {
  flex: 0 0 22px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--theme);
  color: #fff;
  font-size: 13px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
}

.ios-glyph {
  display: inline-block;
  margin: 0 2px;
}

.ios-guide-tip {
  margin: 0 0 16px;
  padding: 10px 12px;
  background: #F9FAFB;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1.7;
  color: var(--text-weak);
}

/* ---------- 兜底自救按钮（iframe 白屏时手动切换打开方式） ---------- */
.rescue-btn {
  position: fixed;
  right: calc(14px + env(safe-area-inset-right));
  bottom: calc(24px + env(safe-area-inset-bottom));
  z-index: 45;
  appearance: none;
  -webkit-appearance: none;
  border: 2px solid rgba(255, 255, 255, 0.9);
  border-radius: 999px;
  padding: 13px 20px;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  line-height: 1;
  color: #fff;
  background: var(--theme);
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3);
  cursor: pointer;
  /* iframe 被拦截时是静默白屏，这个按钮是用户唯一的出路，必须足够显眼、且常驻。
     动效只做 3 次「呼吸」吸引注意后静止：
     无限动画会让元素永远处于「不稳定」状态，自动化工具（以及部分辅助技术）
     无法点击它，属于真实可用性缺陷，因此不能写成 infinite。 */
  animation: rescue-pulse 0.9s ease-in-out 3;
}

@keyframes rescue-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 6px 20px rgba(0, 0, 0, 0.3); }
  50% { transform: scale(1.05); box-shadow: 0 6px 26px rgba(0, 0, 0, 0.42); }
}

/* 尊重系统「减少动态效果」设置 */
@media (prefers-reduced-motion: reduce) {
  .rescue-btn { animation: none; }
}

.rescue-btn:active {
  transform: scale(0.96);
}

/* ---------- 安装引导底部的企业名称（如「惠乔生物科技有限责任公司 · 内部使用」） ---------- */
.guide-company {
  margin: 12px 0 0;
  padding-top: 10px;
  border-top: 1px solid var(--border);
  font-size: 12px;
  line-height: 1.6;
  color: var(--text-weak);
  text-align: center;
  letter-spacing: 0.5px;
}

.ios-guide-panel .guide-company {
  margin-top: 14px;
}

/* ---------- 小屏适配 ---------- */
@media (max-height: 600px) {
  /* 60px 对应圆角 60 × 22.5% ≈ 14px，与标志本体保持一致 */
  .boot-logo { width: 60px; height: 60px; border-radius: 14px; margin-bottom: 16px; }
  .card { padding: 20px 16px; }
}
