/* Sentinel RiskB — Mobile layout polish */

:root {
  --mobile-topbar: 48px;
}

@media (min-width: 1025px) {
  body.sidebar-collapsed .sidebar {
    display: flex !important;
  }
  .mobile-nav-toggle {
    display: none !important;
  }
  .mobile-nav-backdrop {
    display: none !important;
  }
}

@media (max-width: 1024px) {
  .layout,
  .app-layout,
  #app {
    flex-direction: column !important;
    min-height: 0;
  }

  /* —— 顶栏紧凑 —— */
  .topbar,
  .header-bar {
    height: var(--mobile-topbar) !important;
    min-height: var(--mobile-topbar);
    padding: 0 10px !important;
    flex-wrap: nowrap;
    gap: 8px;
  }

  body.is-mobile .topbar .brand {
    padding-right: 8px;
    border-right: none;
    min-width: 0;
    flex: 1;
  }

  body.is-mobile .topbar .brand .org {
    display: none;
  }

  body.is-mobile .topbar .brand .info .name {
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 52vw;
  }

  body.is-mobile .topbar .actions {
    flex-shrink: 0;
    gap: 4px;
  }

  body.is-mobile .topbar .actions button,
  body.is-mobile .lang-btn {
    padding: 4px 10px !important;
    font-size: 10px !important;
  }

  /* —— 主内容铺满，避免与页面内边距叠成「框」 —— */
  .main,
  .content,
  #mainContent {
    width: 100% !important;
    min-width: 0 !important;
    padding: 0 !important;
    padding-bottom: calc(64px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .page.active {
    width: 100%;
  }

  body.is-mobile .page.active > .st {
    font-size: 15px;
    font-weight: 600;
    padding: 10px 12px 6px !important;
    margin: 0;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-light);
  }

  body.is-mobile .page.active > .tbr,
  body.is-mobile .page.active > .mod-tabs {
    position: sticky;
    top: 0;
    z-index: 45;
    margin: 0 !important;
    padding: 8px 12px !important;
    background: var(--bg-main);
    border-bottom: 1px solid var(--border-light);
    box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
  }

  body.is-mobile .page.active > div[id],
  body.is-mobile .page.active > .mod-tabs + .mod-panel {
    padding: 0 12px 14px !important;
  }

  /* —— 侧栏：抽屉（替代顶部横向滚动条） —— */
  body.is-mobile .sidebar {
    position: fixed !important;
    left: 0;
    top: var(--mobile-topbar);
    bottom: 0;
    width: min(288px, 88vw) !important;
    min-width: 0 !important;
    max-height: none !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    overflow-x: hidden !important;
    overflow-y: auto !important;
    padding: 6px 0 calc(20px + env(safe-area-inset-bottom, 0px)) !important;
    gap: 0;
    z-index: 920;
    border-right: 1px solid var(--border);
    border-bottom: none !important;
    box-shadow: 8px 0 28px rgba(15, 23, 42, 0.14);
    transform: translateX(0);
    transition: transform 0.22s ease, visibility 0.22s;
    -webkit-overflow-scrolling: touch;
  }

  body.is-mobile.sidebar-collapsed .sidebar,
  body.is-mobile:not(.mobile-nav-open) .sidebar {
    transform: translateX(-105%);
    visibility: hidden;
    pointer-events: none;
  }

  body.is-mobile.mobile-nav-open .sidebar {
    transform: translateX(0);
    visibility: visible;
    pointer-events: auto;
    display: flex !important;
  }

  body.is-mobile .sidebar .sec {
    display: block !important;
    flex-direction: column !important;
    flex-wrap: nowrap !important;
    width: 100%;
    margin: 0 !important;
    padding: 12px 16px 4px !important;
    border: none !important;
  }

  body.is-mobile .sidebar .ni {
    white-space: normal !important;
    width: 100%;
    padding: 10px 16px !important;
    font-size: 13px !important;
    border-radius: 0 !important;
    min-height: 44px;
    box-sizing: border-box;
  }

  .mobile-nav-backdrop {
    display: none;
    position: fixed;
    left: 0;
    right: 0;
    top: var(--mobile-topbar);
    bottom: 0;
    z-index: 910;
    background: rgba(15, 23, 42, 0.42);
    border: none;
    padding: 0;
    margin: 0;
    cursor: pointer;
  }

  body.is-mobile.mobile-nav-open .mobile-nav-backdrop {
    display: block;
  }

  /* —— 模块 Tab / 统计 —— */
  .tbr {
    display: flex !important;
    gap: 6px !important;
    overflow-x: auto !important;
    flex-wrap: nowrap !important;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
  }

  .tbr::-webkit-scrollbar {
    display: none;
  }

  .tbr .tb {
    flex-shrink: 0;
    font-size: 12px !important;
    padding: 8px 12px !important;
    border-radius: 8px !important;
  }

  body.is-mobile .mod-tabs {
    gap: 6px !important;
  }

  body.is-mobile .mod-tabs-row {
    flex-wrap: nowrap !important;
    overflow-x: auto !important;
    -webkit-overflow-scrolling: touch;
    gap: 6px !important;
    padding-bottom: 2px;
    scrollbar-width: none;
  }

  body.is-mobile .mod-tabs-row::-webkit-scrollbar {
    display: none;
  }

  body.is-mobile .mod-tabs-label {
    flex: 0 0 auto;
    font-size: 10px;
    padding: 4px 8px;
    border-radius: 6px;
    background: var(--bg-surface);
    color: var(--text-muted);
    margin-right: 2px;
  }

  .stats-row,
  .sr {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 8px !important;
    margin-bottom: 12px !important;
  }

  .sc {
    padding: 12px 10px !important;
    border-radius: 10px !important;
  }

  .sc .n {
    font-size: 22px !important;
  }

  .chart-row {
    grid-template-columns: 1fr !important;
    gap: 12px !important;
  }

  .chart-box {
    min-height: 220px;
    padding: 12px !important;
  }

  .mg {
    grid-template-columns: 1fr 1fr !important;
    gap: 8px !important;
  }

  .pn,
  .sec-block,
  .alert-item {
    border-radius: 10px !important;
  }

  .dt {
    display: block;
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table.dt {
    min-width: 520px;
  }

  .divination-form {
    padding: 12px !important;
  }

  .divination-form .form-row {
    gap: 8px;
  }

  .divination-form .form-group {
    min-width: calc(50% - 8px);
  }

  .chat-a,
  .chat-area {
    max-width: 100% !important;
    padding: 0 !important;
  }

  .chat-m,
  .chat-msgs {
    max-height: 55vh !important;
    padding: 8px 10px !important;
  }

  .msg .b,
  .msg-bubble {
    max-width: 90% !important;
    font-size: 14px !important;
  }

  .footer {
    flex-direction: column !important;
    gap: 4px;
    text-align: center;
    font-size: 10px !important;
    padding: 8px 12px !important;
  }

  .tb,
  button.tb,
  .btn-primary,
  .btn-secondary {
    min-height: 40px;
    touch-action: manipulation;
  }

  input,
  select,
  textarea,
  .form-input {
    font-size: 16px !important;
  }

  @media (hover: none) {
    .sc:hover,
    .mc:hover {
      transform: none !important;
      box-shadow: none !important;
    }
  }
}

@media (max-width: 480px) {
  .stats-row,
  .sr {
    grid-template-columns: 1fr 1fr !important;
  }

  .mg {
    grid-template-columns: 1fr !important;
  }

  .sc .n {
    font-size: 20px !important;
  }

  #gaugeWrap,
  .gauge-wrap {
    transform: scale(0.92);
  }

  body.is-mobile .divination-form .form-group {
    min-width: 100%;
  }
}

/* 浮动菜单按钮 */
.mobile-nav-toggle {
  display: none;
}

@media (max-width: 1024px) {
  .mobile-nav-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    bottom: calc(14px + env(safe-area-inset-bottom, 0px));
    right: calc(14px + env(safe-area-inset-right, 0px));
    z-index: 930;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: var(--acc);
    color: #fff;
    border: none;
    box-shadow: 0 4px 16px rgba(13, 159, 110, 0.35);
    font-size: 20px;
    line-height: 1;
    cursor: pointer;
    touch-action: manipulation;
  }

  body.is-mobile.mobile-nav-open .mobile-nav-toggle {
    background: var(--bg-card);
    color: var(--text-bright);
    border: 1px solid var(--border);
    box-shadow: 0 2px 12px rgba(15, 23, 42, 0.12);
  }
}
