/* 业务用户侧（user-portal + auth）响应式；须在各自页面 <style> 之后引入以覆盖固定侧栏等布局 */

/* 认证页主题按钮为 position:fixed，勿在 body 上 clip 以免被裁切 */
body.user-portal:not(.auth-page) {
  overflow-x: clip;
}

body.user-portal {
  margin: 0;
}

/* 已登录壳（存在侧栏）时整页底色与正文字色；登录/注册无侧栏仍由 auth-shell 等负责 */
body.user-portal:has(.sidebar) {
  background: var(--ut-page-bg);
  color: var(--ut-text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
}

body.user-portal .main {
  min-width: 0;
}

body.user-portal .table-container {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  max-width: 100%;
}

body.user-portal .table-container table {
  min-width: 520px;
}

/* 宽屏：顶栏 + 左侧固定导航（夜间默认；浅色下背景/边框由 user-theme.css 的 html[data-user-theme=light] 覆盖） */
@media (min-width: 901px) {
  body.user-portal .header {
    position: fixed;
    z-index: 1000;
    top: 0;
    left: 0;
    right: 0;
    height: 56px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 5%;
    box-sizing: border-box;
    background: var(--ut-header-bg);
    border-bottom: 1px solid rgba(99, 102, 241, 0.18);
    backdrop-filter: blur(14px) saturate(1.25);
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.22), 0 0 0 1px rgba(255, 255, 255, 0.04) inset;
  }

  body.user-portal .logo {
    font-size: 1.28rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    margin: 0;
    background: linear-gradient(135deg, var(--ut-accent-a) 0%, var(--ut-accent-b) 52%, var(--ut-accent-c) 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 0 32px rgba(56, 189, 248, 0.15);
  }

  body.user-portal .user-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
  }

  body.user-portal .user-info span {
    color: var(--ut-muted);
    font-size: 0.9rem;
  }

  body.user-portal .header .user-info button#logoutBtn {
    padding: 0.45rem 0.95rem;
    border-radius: 999px;
    border: 1px solid rgba(248, 113, 113, 0.35);
    background: linear-gradient(180deg, rgba(239, 68, 68, 0.28), rgba(185, 28, 28, 0.18));
    color: #fecaca;
    font-size: 0.82rem;
    cursor: pointer;
    font-family: inherit;
    transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  }

  body.user-portal .header .user-info button#logoutBtn:hover {
    background: linear-gradient(180deg, rgba(239, 68, 68, 0.4), rgba(185, 28, 28, 0.28));
    color: #fff;
    border-color: rgba(252, 165, 165, 0.55);
    box-shadow: 0 4px 16px rgba(239, 68, 68, 0.25);
    transform: translateY(-1px);
  }

  body.user-portal .sidebar {
    position: fixed;
    z-index: 900;
    left: 0;
    top: 56px;
    bottom: 0;
    width: 220px;
    box-sizing: border-box;
    background: var(--ut-sidebar-bg);
    border-right: 1px solid rgba(99, 102, 241, 0.12);
    padding: 0.85rem 0 1.25rem;
    overflow-y: auto;
    box-shadow: 4px 0 32px rgba(0, 0, 0, 0.12);
  }

  body.user-portal .sidebar ul {
    list-style: none;
    margin: 0;
    padding: 0;
  }

  body.user-portal .sidebar li {
    margin: 0;
  }

  body.user-portal .sidebar a {
    display: flex;
    align-items: center;
    gap: 0.55rem;
    padding: 0.62rem 1rem 0.62rem 1.05rem;
    margin: 0.2rem 0.55rem;
    border-radius: 10px;
    color: var(--ut-muted);
    text-decoration: none;
    font-size: 0.9rem;
    border-left: 3px solid transparent;
    transition: background 0.18s ease, color 0.18s ease, box-shadow 0.18s ease, transform 0.15s ease;
  }

  body.user-portal .sidebar a .nav-ico {
    font-size: 1.05rem;
    line-height: 1;
    opacity: 0.88;
    filter: saturate(1.1);
  }

  body.user-portal .sidebar a:hover {
    background: rgba(51, 65, 85, 0.5);
    color: var(--ut-text);
    transform: translateX(2px);
  }

  body.user-portal .sidebar a.active {
    background: linear-gradient(90deg, rgba(59, 130, 246, 0.28), rgba(99, 102, 241, 0.08));
    color: #e0f2fe;
    border-left-color: transparent;
    box-shadow:
      inset 0 0 0 1px rgba(96, 165, 250, 0.35),
      0 6px 20px rgba(37, 99, 235, 0.18);
  }

  body.user-portal .sidebar a.active .nav-ico {
    opacity: 1;
  }

  body.user-portal .main {
    margin-left: 220px;
    margin-top: 56px;
    min-height: calc(100vh - 56px);
    padding: 1.25rem 5% 2rem;
    box-sizing: border-box;
  }
}

@media (max-width: 900px) {
  body.user-portal .header {
    flex-wrap: wrap;
    align-items: flex-start;
    row-gap: 0.5rem;
    padding: 0.75rem 4%;
  }

  body.user-portal .header .logo {
    font-size: clamp(1.1rem, 4.2vw, 1.4rem);
    min-width: 0;
  }

  body.user-portal .user-info {
    flex-wrap: wrap;
    justify-content: flex-end;
    row-gap: 0.5rem;
    column-gap: 0.65rem;
    max-width: 100%;
  }

  /* 顶栏下有侧栏的页面：侧栏改为顶部横向导航，主区全宽 */
  body.user-portal:not(.tg-chat-embed) .sidebar {
    position: relative;
    left: auto;
    top: auto;
    bottom: auto;
    width: 100%;
    height: auto;
    min-height: 0;
    padding: 0.65rem 4%;
    border-bottom: 1px solid rgba(51, 65, 85, 0.85);
  }

  body.user-portal:not(.tg-chat-embed) .sidebar ul {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
    align-items: center;
  }

  body.user-portal:not(.tg-chat-embed) .sidebar li {
    margin-bottom: 0;
  }

  body.user-portal:not(.tg-chat-embed) .sidebar a {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.45rem 0.65rem;
    font-size: 0.82rem;
    white-space: nowrap;
    border-radius: 999px;
  }

  body.user-portal:not(.tg-chat-embed) .main {
    margin-left: 0 !important;
    padding: 1rem 4%;
    width: 100%;
    min-width: 0;
  }

  /* 全屏对话页：主列占满剩余高度 */
  body.user-portal.tg-full-chat {
    min-height: 100vh;
    min-height: 100dvh;
  }

  body.user-portal.tg-full-chat .main {
    flex: 1;
    min-height: 0;
    height: auto;
    max-height: none;
  }

  body.user-portal .stats {
    grid-template-columns: repeat(2, 1fr) !important;
    gap: 1rem;
  }

  body.user-portal .order-body {
    grid-template-columns: repeat(2, 1fr) !important;
  }

  body.user-portal .payment-options {
    grid-template-columns: 1fr !important;
  }

  body.user-portal .dashboard-chat-frame-wrap {
    max-width: 100%;
  }

  body.user-portal iframe.dashboard-chat-frame {
    height: min(75vh, 720px);
    min-height: 280px;
  }

  body.user-portal .filter-bar {
    flex-wrap: wrap;
    gap: 0.65rem;
  }

  body.user-portal .filter-bar input[type="date"],
  body.user-portal .filter-bar select {
    min-width: 0;
    flex: 1 1 140px;
  }

  body.user-portal .title {
    flex-wrap: wrap;
    gap: 0.75rem;
  }

  body.user-portal .title h1 {
    font-size: clamp(1.25rem, 4vw, 1.65rem);
  }

  body.user-portal .level-info {
    flex-wrap: wrap;
    gap: 0.65rem;
    align-items: flex-start;
  }

  body.user-portal .embed-top {
    flex-wrap: wrap;
    row-gap: 0.35rem;
    padding-left: 3%;
    padding-right: 3%;
  }
}

@media (max-width: 600px) {
  body.user-portal .modal-overlay.show {
    padding: max(0.75rem, env(safe-area-inset-left, 0px)) max(0.75rem, env(safe-area-inset-right, 0px));
    align-items: center;
  }

  body.user-portal .payment-modal.show {
    padding: max(0.75rem, env(safe-area-inset-left, 0px)) max(0.75rem, env(safe-area-inset-right, 0px));
  }

  body.user-portal .payment-modal-content {
    width: 100%;
    max-width: 100%;
  }

  body.user-portal .modal {
    max-width: 100%;
  }

  body.user-portal .trend-bars {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    justify-content: flex-start;
    gap: 6px;
    padding-bottom: 6px;
  }

  body.user-portal .order-detail-modal {
    padding: max(0.75rem, env(safe-area-inset-top, 0px)) max(0.75rem, env(safe-area-inset-right, 0px)) max(0.75rem, env(safe-area-inset-bottom, 0px)) max(0.75rem, env(safe-area-inset-left, 0px));
    align-items: flex-start;
    overflow-y: auto;
  }

  body.user-portal .order-detail-modal-content {
    min-width: 0;
    width: 100%;
    max-width: min(520px, 100vw - 1.5rem);
    padding: 1rem;
    max-height: min(85vh, 100dvh - 2rem);
  }

  body.user-portal .order-detail-modal-content .detail-row {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.2rem;
  }

  body.user-portal .order-detail-modal-content .detail-label {
    width: auto;
  }

  body.user-portal .stats {
    grid-template-columns: 1fr !important;
  }

  body.user-portal .order-body {
    grid-template-columns: 1fr !important;
  }

  body.user-portal .quick-actions {
    grid-template-columns: 1fr !important;
  }

  body.user-portal .pagination {
    flex-wrap: wrap;
    row-gap: 0.35rem;
  }

  body.user-portal .pagination button {
    padding: 0.45rem 0.65rem;
    font-size: 0.82rem;
  }

  body.user-portal .key-value {
    flex-direction: column;
    align-items: stretch;
    gap: 0.65rem;
  }

  body.user-portal .key-value button {
    align-self: flex-start;
  }

  body.user-portal .key-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  body.user-portal .key-footer {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.75rem;
  }

  body.user-portal .activity-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.5rem;
  }

  body.user-portal .activity-item .info {
    width: 100%;
  }

  body.user-portal .order-header {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  body.user-portal .order-footer {
    flex-wrap: wrap;
    gap: 0.65rem;
  }

  body.user-portal .input-container {
    flex-direction: column;
  }

  body.user-portal .input-container button {
    width: 100%;
  }

  body.user-portal .message .content {
    max-width: min(92%, 100% - 3rem) !important;
  }

  body.user-portal .chat-toolbar {
    padding-left: 3%;
    padding-right: 3%;
  }

  body.user-portal .chat-container {
    padding-left: 3%;
    padding-right: 3%;
  }

  body.user-portal .input-area {
    padding-left: 3%;
    padding-right: 3%;
  }

  body.user-portal th,
  body.user-portal td {
    padding: 0.65rem 0.5rem;
    font-size: 0.85rem;
  }

  body.user-portal .balance-card .value {
    font-size: clamp(1.5rem, 8vw, 2.25rem);
  }

  body.user-portal .pricing-recharge .plan .price {
    font-size: clamp(1.75rem, 9vw, 2.5rem);
  }
}

/* 登录 / 注册：无侧栏，压缩内边距与表单 */
@media (max-width: 600px) {
  body.user-portal.auth-page .wrapper {
    padding: 1rem;
    align-items: flex-start;
    padding-top: max(1rem, env(safe-area-inset-top, 0px));
  }

  body.user-portal.auth-page .container {
    padding: 1.5rem 1.15rem;
    border-radius: 12px;
  }

  body.user-portal.auth-page .back-home {
    position: relative;
    top: auto;
    left: auto;
    margin-bottom: 0.75rem;
    display: inline-flex;
  }

  body.user-portal.auth-page .sms-row {
    flex-direction: column;
  }

  body.user-portal.auth-page .btn-sms {
    width: 100%;
  }

  body.user-portal.auth-page .footer-links {
    flex-wrap: wrap;
    gap: 1rem;
    justify-content: center;
  }
}

/* 全屏 / 嵌入对话：避免工具栏内原生 select 底边被裁切或与下边框线「粘死」
   body 默认 overflow-x: clip 时，规范会将另一轴 overflow 按非 visible 处理，易竖向裁切控件 */
body.user-portal.tg-full-chat:not(.auth-page),
body.user-portal.tg-chat-embed:not(.auth-page) {
  overflow: visible;
}

/* 窄屏下工具栏单行横向滚动；竖向不裁切，避免压住原生 select 等控件 */
body.user-portal.tg-full-chat .chat-toolbar,
body.user-portal.tg-chat-embed .chat-toolbar,
body.user-portal.tg-full-chat .session-toolbar,
body.user-portal.tg-chat-embed .session-toolbar,
.tg-chat-embed .chat-toolbar,
.tg-chat-embed .session-toolbar {
  overflow-x: auto;
  overflow-y: visible;
  -webkit-overflow-scrolling: touch;
}

body.user-portal.tg-full-chat .chat-toolbar:not(.session-toolbar) {
  padding: 0.7rem 5%;
}

body.user-portal.tg-full-chat .chat-toolbar.session-toolbar {
  padding: 0.7rem 5% 1rem;
}

body.user-portal.tg-chat-embed .chat-toolbar:not(.session-toolbar) {
  padding: 0.7rem 4%;
}

body.user-portal.tg-chat-embed .chat-toolbar.session-toolbar {
  padding: 0.7rem 4% 1rem;
}

body.user-portal.tg-full-chat .chat-toolbar select,
body.user-portal.tg-chat-embed .chat-toolbar select,
body.user-portal.tg-full-chat .session-toolbar select,
body.user-portal.tg-chat-embed .session-toolbar select {
  line-height: 1.35;
  min-height: 2.375rem;
}

/* 嵌入对话顶栏（与 ChatEmbedLayout 类名一致） */
.tg-chat-embed {
  min-height: 100vh;
  background:
    radial-gradient(ellipse 90% 40% at 50% 0%, rgba(56, 189, 248, 0.12), transparent 55%),
    linear-gradient(180deg, #0a0f1a 0%, #0f172a 35%, #111827 100%);
  color: #e2e8f0;
}

.tg-chat-embed-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.55rem 1.15rem;
  background: rgba(15, 23, 42, 0.88);
  border-bottom: 1px solid rgba(99, 102, 241, 0.22);
  backdrop-filter: blur(12px) saturate(1.2);
  font-size: 0.88rem;
  letter-spacing: 0.01em;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.25);
}

.tg-chat-embed-top .tg-chat-embed-brand {
  font-weight: 700;
  background: linear-gradient(135deg, #7dd3fc, #a5b4fc, #e9d5ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tg-chat-embed-top a {
  color: #93c5fd;
  text-decoration: none;
  font-weight: 500;
  padding: 0.35rem 0.65rem;
  border-radius: 999px;
  border: 1px solid rgba(147, 197, 253, 0.35);
  background: rgba(59, 130, 246, 0.12);
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

.tg-chat-embed-top a:hover {
  background: rgba(59, 130, 246, 0.22);
  border-color: rgba(147, 197, 253, 0.55);
  box-shadow: 0 0 20px rgba(59, 130, 246, 0.2);
}

html[data-user-theme="light"] .tg-chat-embed {
  background:
    radial-gradient(ellipse 90% 35% at 50% 0%, rgba(59, 130, 246, 0.1), transparent 50%),
    linear-gradient(180deg, #f8fafc 0%, #f1f5f9 100%);
  color: var(--ut-text, #0f172a);
}

html[data-user-theme="light"] .tg-chat-embed-top {
  background: rgba(255, 255, 255, 0.92);
  border-bottom-color: #e2e8f0;
  box-shadow: 0 4px 20px rgba(15, 23, 42, 0.06);
}

html[data-user-theme="light"] .tg-chat-embed-top a {
  color: #1d4ed8;
  border-color: rgba(59, 130, 246, 0.35);
  background: rgba(239, 246, 255, 0.95);
}

/* 分页（订单 / 消费等共用） */
body.user-portal .pagination {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

body.user-portal .pagination button {
  padding: 0.45rem 0.8rem;
  border-radius: 10px;
  border: 1px solid rgba(71, 85, 105, 0.85);
  background: rgba(15, 23, 42, 0.55);
  color: #e2e8f0;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.86rem;
  transition: background 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease, transform 0.12s ease;
}

body.user-portal .pagination button:hover:not(:disabled) {
  background: rgba(51, 65, 85, 0.75);
  border-color: rgba(148, 163, 184, 0.45);
}

body.user-portal .pagination button.active {
  background: linear-gradient(135deg, #2563eb, #6366f1);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 4px 18px rgba(37, 99, 235, 0.38);
}

body.user-portal .pagination button:disabled {
  opacity: 0.38;
  cursor: not-allowed;
}
