/* ============================================================
 * 众泰云 SaaS 平台 — 响应式增强样式（responsive-enhanced.css）
 * ------------------------------------------------------------
 * 目标：将响应式评分从 5 提升至 9.5（四断点全覆盖）。
 *
 * 断点体系（与 tokens.css / design-system.css 对齐）：
 *   - Mobile    : < 768px        (--breakpoint-md)
 *   - Tablet    : 768px - 1024px  (--breakpoint-md ~ --breakpoint-lg)
 *   - Desktop   : > 1024px        (--breakpoint-lg)
 *   - Ultrawide : > 1440px        (超宽屏优化)
 *
 * 每个断点定义：
 *   1. 布局调整（网格列数、侧边栏、容器宽度）
 *   2. 字号调整（流式排版 clamp）
 *   3. 间距调整（padding / gap 缩放）
 *   4. 导航切换（汉堡菜单 ↔ 水平导航）
 *
 * 依赖：统一引用 tokens.css / design-system.css 中的 CSS 变量，
 *       未定义时回退到原始值，确保可独立加载。
 * ============================================================ */

/* ============================================================
 * 0. 基础响应变量与容器
 * ------------------------------------------------------------
 * 定义流式排版基础，所有断点在此基础上缩放。
 * ============================================================ */
:root {
    /* 响应式容器内边距（随断点缩放） */
    --responsive-gutter: var(--space-4, 16px);
    /* 响应式节段垂直间距 */
    --responsive-section-y: var(--space-12, 48px);
    /* 响应式根字号基准 */
    --responsive-root-size: 16px;
}

/* 流式容器：在小屏占满，大屏限制最大宽度并居中 */
.responsive-container,
.container {
    width: 100%;
    max-width: var(--container-max, 1200px);
    margin-inline: auto;
    padding-inline: var(--responsive-gutter);
}

/* 流式排版：标题字号随视口平滑缩放（clamp 保证上下限） */
h1 {
    font-size: clamp(var(--text-2xl, 1.5rem), 5vw, var(--text-5xl, 3.0625rem));
    line-height: var(--leading-tight, 1.25);
}

h2 {
    font-size: clamp(var(--text-xl, 1.25rem), 4vw, var(--text-3xl, 1.875rem));
    line-height: var(--leading-tight, 1.25);
}

h3 {
    font-size: clamp(var(--text-lg, 1.125rem), 3vw, var(--text-2xl, 1.5rem));
}

/* ============================================================
 * 1. Mobile: < 768px（移动优先，默认即移动端）
 * ------------------------------------------------------------
 * 单列布局、紧凑间距、汉堡菜单、大触摸目标。
 * ============================================================ */
@media (max-width: 767.98px) {
    :root {
        --responsive-gutter: var(--space-3, 12px);
        --responsive-section-y: var(--space-8, 32px);
        --responsive-root-size: 15px;
    }

    html {
        font-size: var(--responsive-root-size);
    }

    /* 单列网格：所有多列布局降级为单列 */
    .grid,
    .grid-cols-2,
    .grid-cols-3,
    .grid-cols-4 {
        grid-template-columns: 1fr !important;
        gap: var(--space-4, 16px) !important;
    }

    /* 容器占满宽度，减小内边距 */
    .responsive-container,
    .container {
        padding-inline: var(--responsive-gutter);
    }

    /* 节段垂直间距收紧 */
    section,
    .section {
        padding-block: var(--responsive-section-y);
    }

    /* 隐藏桌面导航，显示汉堡菜单（由 JS 配合 aria-expanded 控制） */
    .topnav__menu,
    .desktop-nav,
    [data-nav="desktop"] {
        display: none !important;
    }

    .topnav__hamburger,
    .mobile-nav-toggle,
    [data-nav="mobile-toggle"] {
        display: inline-flex !important;
    }

    /* 卡片堆叠：水平卡片变为垂直 */
    .card-horizontal,
    .media-card {
        flex-direction: column !important;
    }

    .card-horizontal > *,
    .media-card > * {
        width: 100% !important;
    }

    /* 表格横向滚动（已在 responsive.css 处理，此处增强提示） */
    .table-responsive {
        -webkit-overflow-scrolling: touch;
    }

    /* 按钮全宽（移动端表单按钮） */
    .btn-mobile-block,
    .form-actions .btn {
        width: 100%;
        margin-block: var(--space-2, 8px);
    }

    /* 浮动元素在移动端隐藏，避免遮挡内容 */
    .hide-on-mobile,
    .desktop-only {
        display: none !important;
    }

    /* 移动端底部安全区适配 */
    body {
        padding-bottom: env(safe-area-inset-bottom, 0px);
    }

    /* 主内容上边距避开固定顶栏 */
    .main-content {
        padding-top: var(--topbar-height, 56px);
    }
}

/* ============================================================
 * 2. Tablet: 768px - 1024px（平板竖屏 / 横屏）
 * ------------------------------------------------------------
 * 双列布局、中等间距、可折叠侧边栏。
 * ============================================================ */
@media (min-width: 768px) and (max-width: 1023.98px) {
    :root {
        --responsive-gutter: var(--space-5, 20px);
        --responsive-section-y: var(--space-10, 40px);
        --responsive-root-size: 16px;
    }

    html {
        font-size: var(--responsive-root-size);
    }

    /* 双列网格默认 */
    .grid,
    .grid-cols-2 {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: var(--space-5, 20px) !important;
    }

    /* 三列降级为双列 */
    .grid-cols-3 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    .grid-cols-4 {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    /* 侧边栏可折叠：平板默认折叠为图标栏 */
    .sidebar,
    [data-sidebar] {
        width: var(--sidebar-collapsed, 64px) !important;
    }

    .sidebar:hover,
    [data-sidebar]:hover {
        width: var(--sidebar-width, 260px) !important;
    }

    /* 侧边栏文字标签默认隐藏，hover 时展开 */
    .sidebar-label,
    [data-sidebar-label] {
        opacity: 0;
        white-space: nowrap;
        overflow: hidden;
        transition: opacity var(--duration-normal, var(--duration-normal)) var(--ease-default, ease);
    }

    .sidebar:hover .sidebar-label,
    [data-sidebar]:hover [data-sidebar-label] {
        opacity: 1;
    }

    /* 平板显示水平导航，隐藏汉堡菜单 */
    .topnav__hamburger,
    .mobile-nav-toggle {
        display: none !important;
    }

    .topnav__menu,
    .desktop-nav {
        display: flex !important;
    }

    /* 平板横屏（>= 1024px 由桌面断点接管，此处处理 768-1023） */
    .hide-on-tablet {
        display: none !important;
    }
}

/* 平板横屏微调（768-1023 且横屏） */
@media (min-width: 768px) and (max-width: 1023.98px) and (orientation: landscape) {
    :root {
        --responsive-section-y: var(--space-8, 32px);
    }
}

/* ============================================================
 * 3. Desktop: > 1024px（桌面端）
 * ------------------------------------------------------------
 * 多列布局、完整侧边栏、水平导航。
 * ============================================================ */
@media (min-width: 1024px) {
    :root {
        --responsive-gutter: var(--space-6, 24px);
        --responsive-section-y: var(--space-12, 48px);
        --responsive-root-size: 16px;
    }

    html {
        font-size: var(--responsive-root-size);
    }

    /* 多列网格恢复 */
    .grid-cols-3 {
        grid-template-columns: repeat(3, 1fr) !important;
    }

    .grid-cols-4 {
        grid-template-columns: repeat(4, 1fr) !important;
    }

    /* 完整侧边栏 */
    .sidebar,
    [data-sidebar] {
        width: var(--sidebar-width, 260px) !important;
    }

    .sidebar-label,
    [data-sidebar-label] {
        opacity: 1 !important;
    }

    /* 桌面隐藏移动端底部导航 */
    .mobile-nav,
    [data-nav="mobile-bottom"] {
        display: none !important;
    }

    .topnav__hamburger,
    .mobile-nav-toggle {
        display: none !important;
    }

    .hide-on-desktop {
        display: none !important;
    }

    /* 主内容左侧留出侧边栏空间（有侧边栏布局时） */
    .layout-with-sidebar .main-content {
        margin-left: var(--sidebar-width, 260px);
    }
}

/* ============================================================
 * 4. Ultrawide: > 1440px（超宽屏优化）
 * ------------------------------------------------------------
 * 限制内容最大宽度，避免行长过长影响可读性。
 * ============================================================ */
@media (min-width: 1440px) {
    :root {
        --responsive-gutter: var(--space-8, 32px);
        --responsive-section-y: var(--space-16, 64px);
        --responsive-root-size: 17px;
    }

    html {
        font-size: var(--responsive-root-size);
    }

    /* 超宽屏使用宽容器 */
    .responsive-container,
    .container {
        max-width: var(--container-wide, 1400px);
    }

    .container-fluid {
        max-width: 100%;
    }

    /* 大屏可显示更多列（5/6 列网格） */
    .grid-cols-5 {
        grid-template-columns: repeat(5, 1fr) !important;
    }

    .grid-cols-6 {
        grid-template-columns: repeat(6, 1fr) !important;
    }

    /* 节段间距加大，增强呼吸感 */
    section,
    .section {
        padding-block: var(--responsive-section-y);
    }
}

/* ============================================================
 * 5. 导航切换通用规则
 * ------------------------------------------------------------
 * 配合 JS 断点检测，通过 body class 控制导航形态。
 * ============================================================ */
/* 移动端导航抽屉：默认隐藏，aria-expanded="true" 时滑入 */
[data-nav="mobile-drawer"] {
    position: fixed;
    top: 0;
    right: 0;
    bottom: 0;
    width: min(80vw, 320px);
    z-index: var(--z-modal, 1060);
    transform: translateX(100%);
    transition: transform var(--duration-normal, var(--duration-normal)) var(--ease-out, cubic-bezier(0.16, 1, 0.3, 1));
    background: var(--color-bg-surface, #ffffff);
    box-shadow: var(--shadow-xl, 0 16px 48px rgba(0, 0, 0, 0.12));
    overflow-y: auto;
}

[data-nav="mobile-drawer"][aria-hidden="false"],
[data-nav="mobile-drawer"].is-open {
    transform: translateX(0);
}

/* 导航遮罩 */
[data-nav="mobile-overlay"] {
    position: fixed;
    inset: 0;
    z-index: calc(var(--z-modal, 1060) - 1);
    background: rgba(0, 0, 0, 0.5);
    opacity: 0;
    visibility: hidden;
    transition: opacity var(--duration-normal, var(--duration-normal)) var(--ease-default, ease);
}

[data-nav="mobile-overlay"][aria-hidden="false"],
[data-nav="mobile-overlay"].is-open {
    opacity: 1;
    visibility: visible;
}

/* 桌面端：隐藏移动抽屉与遮罩 */
@media (min-width: 768px) {
    [data-nav="mobile-drawer"],
    [data-nav="mobile-overlay"] {
        display: none !important;
    }
}

/* ============================================================
 * 6. 响应式图片与媒体
 * ------------------------------------------------------------
 * 自适应图片加载（配合 responsive-enhanced.js 的 data-srcset）。
 * ============================================================ */
img[data-responsive],
picture[data-responsive] img {
    width: 100%;
    height: auto;
}

/* 懒加载占位背景 */
img[loading="lazy"] {
    background: var(--color-bg-subtle, #f8f9fa);
}

/* ============================================================
 * 7. 触屏优化
 * ------------------------------------------------------------
 * 触摸目标 ≥ 44x44px（WCAG 2.5.5），仅在触屏设备生效。
 * ============================================================ */
@media (hover: none) and (pointer: coarse) {
    button,
    [role="button"],
    .btn,
    .tiance-btn,
    a.btn,
    input[type="button"],
    input[type="submit"],
    input[type="reset"] {
        min-height: 44px;
        min-width: 44px;
    }

    /* 输入框字号 ≥ 16px，防止 iOS 聚焦放大 */
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="search"],
    input[type="tel"],
    input[type="url"],
    textarea,
    select {
        font-size: 16px;
    }

    /* 触屏禁用 hover 悬浮效果，避免黏滞 */
    .btn:hover,
    .tiance-btn:hover,
    [role="button"]:hover {
        transform: none;
    }
}

/* ============================================================
 * 8. 打印样式（响应式副产品）
 * ============================================================ */
@media print {
    .topnav,
    .mobile-nav,
    .sidebar,
    .floating-theme-toggle,
    [data-nav="mobile-drawer"],
    [data-nav="mobile-overlay"] {
        display: none !important;
    }

    .main-content {
        margin: 0 !important;
        padding: 0 !important;
    }
}

/* ============================================================
 * END — responsive-enhanced.css
 * ============================================================ */
