@charset "utf-8";
/* ═══════════ 移动端适配（iOS Safari / Android Chrome / 微信内置浏览器） ═══════════
   必须最后引入，覆盖其它样式表。 */

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, .pill-btn, .seg-btn, .home-card, .quick button, .fl-btn {
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
img, svg, video, canvas { max-width: 100%; }

/* 触屏设备没有 hover：始终显示步骤卡片上的操作按钮 */
@media (hover: none) {
  .fl-step-act { opacity: 1 !important; }
  .pillar:hover, .home-card:hover, .history-item:hover, .fl-item:hover { transform: none; }
}

/* ═══ 平板及以下 ═══ */
@media (max-width: 900px) {
  html, body { height: auto; min-height: 100%; }
  body {
    min-height: 100vh; min-height: 100dvh;
    overflow-x: hidden;
    background-attachment: scroll;          /* iOS 不支持 fixed 背景，会闪烁 */
  }
  .grain { display: none; }                  /* 全屏混合模式层在手机上很卡 */

  .topbar {
    height: 56px; padding: 0 14px;
    padding-left: max(14px, env(safe-area-inset-left));
    padding-right: max(14px, env(safe-area-inset-right));
    gap: 8px;
  }
  .brand { gap: 10px; min-width: 0; }
  .seal { width: 36px; height: 36px; font-size: 20px; border-radius: 11px; flex: none; }
  .brand-txt { min-width: 0; }
  .brand-txt h1 { font-size: 19px; letter-spacing: 3px; white-space: nowrap; }
  .brand-txt .sub {
    display: block; font-size: 10.5px; letter-spacing: 1px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .topbar-right { gap: 6px; flex: none; }
  .topbar-right .badge {
    font-size: 12px; padding: 6px 12px; letter-spacing: 1px; white-space: nowrap;
    font-family: inherit;
  }

  .layout {
    padding: 8px;
    padding-left: max(8px, env(safe-area-inset-left));
    padding-right: max(8px, env(safe-area-inset-right));
    padding-bottom: max(8px, env(safe-area-inset-bottom));
    gap: 10px;
    min-width: 0;
  }
  .layout > * { min-width: 0; }

  /* 详批页：整屏固定，对话区内部滚动 */
  body.in-chat { height: 100vh; height: 100dvh; overflow: hidden; }
  body.in-chat .layout {
    height: calc(100vh - 56px); height: calc(100dvh - 56px);
    overflow: hidden;
  }

  /* 其余子页：整页滚动，面板随内容增高 */
  body.in-home .panel, body.in-paipan .panel, body.in-chart .panel,
  body.in-qimen .panel, body.in-liuren .panel, body.in-ziwei .panel { overflow: visible; }
  .panel { border-radius: 16px; }
  .panel-head { border-radius: 16px 16px 0 0; }
  .form-scroll, .chart-scroll { overflow: visible; flex: none; }
  body.in-chat .panel-chart .chart-scroll { overflow-y: auto; flex: 1; }

  /* 命盘抽屉 */
  body.in-chat.show-chart .panel-chart {
    left: 8px; right: 8px;
    height: 86vh; height: 86dvh;
    padding-bottom: env(safe-area-inset-bottom);
    overflow: hidden;
  }
}

/* ═══ 手机 ═══ */
@media (max-width: 640px) {
  /* 顶栏 / 面板头 */
  #aiBadge { display: none; }
  .panel-head { padding: 12px 12px 11px; gap: 8px; min-width: 0; }
  .panel-head .ornament { display: none; }
  .panel-head h2 {
    flex: 1; min-width: 0; text-align: center;
    font-size: 15px; letter-spacing: 2px;
    overflow: hidden; text-overflow: ellipsis;
  }
  .pill-btn { padding: 7px 12px 7px 10px; font-size: 13px; letter-spacing: 1px; gap: 4px; }
  .pill-seal { letter-spacing: 1px; }
  .chart-tag { flex: 0 1 auto; min-width: 0; max-width: 32%; font-size: 11px; padding: 4px 9px; }
  .now-bar { padding: 8px 12px; align-items: flex-start; }
  .now-text { overflow-wrap: anywhere; line-height: 1.5; }

  /* 表单：16px 字号防止 iOS 聚焦时自动放大页面 */
  input[type=text], input[type=number], input[type=search], input[type=password],
  input[type=datetime-local], input[type=date], input[type=time],
  select, textarea, .qm-input, .adm-input {
    font-size: 16px; min-width: 0; max-width: 100%;
  }
  input[type=datetime-local], input[type=date], input[type=time], select {
    -webkit-appearance: none; appearance: none;
    min-height: 44px; line-height: 1.3;
  }
  select {
    padding-right: 32px;
    background-image: linear-gradient(45deg, transparent 50%, #8b87a8 50%),
                      linear-gradient(135deg, #8b87a8 50%, transparent 50%);
    background-position: calc(100% - 17px) 55%, calc(100% - 12px) 55%;
    background-size: 5px 5px, 5px 5px;
    background-repeat: no-repeat;
  }
  input[type=datetime-local]::-webkit-date-and-time-value { text-align: left; min-height: 1.3em; }
  .form-scroll { padding: 16px 14px 20px; }
  .chart-scroll { padding: 14px 12px 20px; }
  .home-scroll { padding: 16px 12px 22px; }
  .fgroup { margin-bottom: 16px; }
  .row3 { grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr) minmax(0, 1fr); }
  .row2 { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .qm-time-row { gap: 8px; min-width: 0; }
  .qm-time-row .qm-input { flex: 1 1 auto; min-width: 0; width: auto; }
  .qm-now-btn { padding: 0 14px; min-height: 44px; white-space: nowrap; }
  .seg-btn { padding: 10px 4px; min-width: 0; letter-spacing: 0; font-size: 13px; }
  .btn-primary { padding: 14px 10px; letter-spacing: 6px; }
  .check { flex-wrap: wrap; }
  .note, .err { overflow-wrap: anywhere; }

  /* 主页卡片：minmax(260px) 在窄屏会撑破容器 */
  .home-cards { grid-template-columns: minmax(0, 1fr); gap: 12px; }
  .home-card { padding: 16px 14px; gap: 12px; }
  .home-card-seal { width: 46px; height: 46px; font-size: 16px; border-radius: 14px; }
  .home-card-title { font-size: 15.5px; letter-spacing: 2px; }
  .home-card-desc { overflow-wrap: anywhere; }

  /* 命盘 */
  .basic-bar { padding: 12px 14px; gap: 6px 16px; }
  .basic-bar .bi { overflow-wrap: anywhere; }
  .pillars { gap: 8px; }
  .pillar { min-width: 0; }
  .pillar .p-gan { font-size: 28px; }
  .pillar .p-zhi { font-size: 24px; }
  .pillar .p-meta { padding: 8px 8px; overflow-wrap: anywhere; }
  .pillar .p-meta .m { flex-wrap: wrap; gap: 0 6px; }
  .card { padding: 12px 13px; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .kv { gap: 2px 10px; }
  .kv > * { min-width: 0; overflow-wrap: anywhere; }
  .wx-row { grid-template-columns: 30px minmax(0, 1fr) 64px; gap: 8px; }
  .tbl th, .tbl td { padding: 7px 7px; }
  .tag { white-space: normal; }

  /* 历史记录 */
  .history { padding: 14px 12px 8px; }
  .history-item { padding: 10px; gap: 8px; }
  .hi-main { flex: 1; }
  .hi-gz { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; letter-spacing: 1px; }
  .hi-del { width: 30px; height: 30px; font-size: 18px; }
  .hi-time { white-space: nowrap; }

  /* 对话 */
  .chat-log { padding: 14px 12px; gap: 14px; }
  .chat-log > * { min-width: 0; }
  .msg { min-width: 0; }
  .msg-body {
    font-size: 14px; line-height: 1.85; padding: 11px 13px; min-width: 0;
    overflow-wrap: anywhere; word-break: break-word;
  }
  .msg-user .msg-body { max-width: 92%; }
  .msg-body.md .md-p { text-align: left; }
  .msg-body.md .md-table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .msg-body.md .md-pre { max-width: 100%; }
  .msg-body.md .md-h1 { font-size: 16px; }
  .msg-body.md .md-h2 { font-size: 15px; }
  .chat-input {
    padding: 10px 12px 6px; gap: 8px; min-width: 0;
  }
  .chat-input textarea { min-width: 0; font-size: 16px; }
  .btn-send { width: 44px; height: 44px; }
  .depth-bar { padding: 8px 12px 0; gap: 6px; }
  .depth-seg { flex: 1 1 100%; }
  .depth-seg .seg-btn { font-size: 12px; padding: 9px 2px; }
  .quick {
    padding: 4px 12px 14px; gap: 7px;
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }
  .quick button { padding: 8px 12px; font-size: 13px; }
  .ask-card { padding: 12px 10px 10px; }
  .ask-opt { padding: 10px; }
  .ask-opt > *, .ask-txt { min-width: 0; overflow-wrap: anywhere; }
  .ask-other { flex-wrap: nowrap; }
  .ask-input { font-size: 16px; }
  .ask-submit { padding: 9px 22px; }

  /* 奇门 / 六壬 / 紫微 */
  .qm-grid { gap: 5px; }
  .qm-cell { padding: 6px 5px; min-height: 120px; overflow: hidden; overflow-wrap: anywhere; }
  .qm-tags { gap: 2px; }
  .zw-cell { padding: 4px 3px 3px; overflow: hidden; }
  .zw-misc, .zw-pname { overflow-wrap: anywhere; }
  .zw-foot { flex-wrap: wrap; }
  .zw-center { padding: 6px 4px; overflow: hidden; overflow-wrap: anywhere; }
  .zw-center b { font-size: 14px; letter-spacing: 1px; }
  .zw-row { grid-template-columns: 78px minmax(0, 1fr); }
  .zw-pat { flex-wrap: wrap; }
  .zw-score { grid-template-columns: 32px minmax(0, 1fr) 28px; }
  .lr-ring { gap: 4px; }
  .lr-cell { padding: 5px 2px; overflow: hidden; }
  .lr-center { overflow: hidden; padding: 6px 4px; }
  .lr-center b { font-size: 15px; letter-spacing: 1px; }
  .lr-ke { gap: 5px; }
  .lr-ke-up, .lr-ke-low { font-size: 19px; }
  .lr-chuan { gap: 5px; }
  .lr-chuan-main { font-size: 22px; }

  /* 设置抽屉 */
  .st-drawer { width: 100vw; border-radius: 0; border-left: 0; }
  .st-head { padding: 13px 14px; padding-top: max(13px, env(safe-area-inset-top)); }
  .st-tabs {
    padding: 10px 14px 0; gap: 4px;
    overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: none;
  }
  .st-tabs::-webkit-scrollbar { display: none; }
  .st-tab { flex: none; padding: 9px 13px; letter-spacing: 1px; white-space: nowrap; }
  .st-body { padding: 16px 14px 22px; }
  .st-flow-editor-host { margin: -16px -14px -22px; }
  .st-fl-ed-bar { padding: 10px 14px; flex-wrap: wrap; }
  .st-flow-editor-host .fl-editor-body { padding: 14px 14px 70px; }
  .st-pf, .st-flow-item { flex-wrap: wrap; padding: 11px 12px; }
  .st-pf-main, .st-flow-main { flex: 1 1 140px; }
  .st-pf-act, .st-flow-act { flex: 1 1 100%; justify-content: flex-start; flex-wrap: wrap; }
  .st-foot {
    padding: 10px 14px; padding-bottom: max(10px, env(safe-area-inset-bottom));
    gap: 8px; flex-wrap: wrap;
  }
  .st-msg { overflow-wrap: anywhere; min-width: 0; }
  .st-ac { top: auto; }
  .st-ac-item { flex-wrap: wrap; }
  .st-ac-desc { white-space: normal; }
  .st-field input, .st-field select, .st-field textarea { font-size: 16px; }
  #promptText { font-size: 14px; }
  .st-model { padding: 5px 11px; }

  /* 流程库 */
  .fl-layout { height: auto; }
  .fl-side { border-right: 0; border-bottom: 1px solid var(--line); }
  .fl-list { max-height: 46vh; max-height: 46dvh; }
  .fl-editor-body { padding: 14px 12px 90px; }
  .fl-sec { padding: 13px 12px; margin-bottom: 16px; }
  .fl-sec-head { flex-wrap: wrap; gap: 8px; }
  .fl-sec-act { flex-wrap: wrap; }
  .fl-foot {
    margin: 0 -12px -90px; padding: 11px 12px; gap: 8px; flex-wrap: wrap;
    padding-bottom: max(11px, env(safe-area-inset-bottom));
  }
  .fl-foot-btns { flex-wrap: wrap; }
  .fl-btn { padding: 8px 14px; }
  .fl-btn.mini { padding: 5px 11px; }
  .fl-field input, .fl-field select, .fl-field textarea { font-size: 16px; }
  .fl-step-top, .fl-out-top, .fl-node-top { flex-wrap: wrap; }
  .fl-step-name, .fl-out-name, .fl-node-name { min-width: 0; overflow-wrap: anywhere; }
  .fl-out-tpl { overflow-wrap: anywhere; }
  .fl-branch-row { flex-wrap: wrap; }
  .fl-branch-row input[type="text"], .fl-branch-row select { flex: 1 1 120px; }
  .fl-dkey .dk-desc { max-width: 100%; }
  .fl-modal { padding: 10px; align-items: flex-end; }
  .fl-modal-box { max-height: 92vh; max-height: 92dvh; }
  .fl-modal-head { padding: 13px 14px; }
  .fl-modal-body { padding: 14px; }
  .fl-modal-foot {
    padding: 12px 14px; flex-wrap: wrap;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
  .fl-tip code { overflow-wrap: anywhere; }

  /* 对话日志 */
  .lg-kv { grid-template-columns: 78px minmax(0, 1fr); gap: 4px 10px; }
  .lg-item-sub span { white-space: normal; }
  .lg-detail-head { flex-wrap: wrap; }
  .lg-entry-title { overflow-wrap: anywhere; }

  /* 管理员登录框 */
  .adm-box { padding: 20px 16px 16px; }
}

/* ═══ 小屏手机（iPhone SE / 360px 以下） ═══ */
@media (max-width: 400px) {
  .brand-txt .sub { display: none; }
  .brand-txt h1 { font-size: 18px; letter-spacing: 2px; }
  .topbar-right .badge { padding: 6px 10px; }
  .pill-btn { padding: 6px 10px 6px 8px; font-size: 12.5px; }
  .chart-tag { max-width: 26%; }
  .row2 { grid-template-columns: minmax(0, 1fr); }
  .pillars { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .pillar .p-gan { font-size: 26px; }
  .qm-cell { padding: 5px 4px; min-height: 112px; font-size: 11px; }
  .zw-star { font-size: 11px; }
  .zw-star.zw-aux, .zw-star.zw-sha { font-size: 10px; }
  .zw-cell { min-height: 96px; }
  .lr-tian { font-size: 15px; }
  .msg-user .msg-body { max-width: 96%; }
  .fl-tabs { flex-wrap: wrap; }
}

/* 横屏手机：降低顶栏占高 */
@media (max-width: 900px) and (orientation: landscape) and (max-height: 500px) {
  .topbar { height: 48px; }
  body.in-chat .layout { height: calc(100vh - 48px); height: calc(100dvh - 48px); }
  body.in-chat.show-chart .panel-chart { height: 92vh; height: 92dvh; }
}
