/* ============================================
   MOBILE RESPONSIVE STYLES
   Campus Management System
   专门为手机端优化的CSS样式
   ============================================ */

/* ============================================
   移动端基础设置
   ============================================ */
@media (max-width: 768px) {
    /* 防止页面缩放 */
    * {
        -webkit-tap-highlight-color: transparent;
        -webkit-touch-callout: none;
    }
    
    body {
        font-size: 14px;
        overflow-x: hidden;
    }
    
    /* 容器调整 */
    .container {
        padding: 0 15px;
        margin-top: 15px;
    }
}

/* ============================================
   顶部导航栏 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .header {
        padding: 12px 0;
        margin-bottom: 20px;
        position: sticky;
        top: 0;
        z-index: 999;
    }
    
    .header-content {
        flex-direction: column;
        gap: 12px;
        padding: 0 15px;
    }
    
    /* Logo部分 */
    .logo-section {
        width: 100%;
        justify-content: center;
        gap: 10px;
    }
    
    .logo-icon {
        width: 45px;
        height: 45px;
        font-size: 24px;
    }
    
    .logo-text h1 {
        font-size: 18px;
        white-space: nowrap;
    }
    
    .logo-text p {
        font-size: 11px;
        display: none; /* 手机端隐藏副标题 */
    }
    
    /* 用户信息部分 */
    .user-section {
        width: 100%;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        gap: 10px;
    }
    
    .user-info {
        text-align: left;
        flex: 1;
    }
    
    .user-name {
        font-size: 14px;
    }
    
    .user-role {
        font-size: 12px;
    }
    
    .logout-btn {
        padding: 8px 16px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
    }
    
    /* 设置下拉菜单 - 移动端 */
    .settings-dropdown {
        flex-shrink: 0;
    }
    
    .dropdown-menu {
        position: fixed;
        top: auto;
        right: 10px;
        left: 10px;
        width: auto;
        max-width: none;
    }
    
    .dropdown-item {
        padding: 15px 20px;
        font-size: 15px;
    }
    
    .dropdown-item i {
        font-size: 18px;
    }
}

/* ============================================
   登录页面 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .login-container {
        padding: 20px 15px;
    }
    
    .login-box {
        padding: 30px 20px;
        border-radius: 16px;
    }
    
    .login-logo-icon {
        width: 60px;
        height: 60px;
        font-size: 32px;
        margin-bottom: 15px;
    }
    
    .login-logo h1 {
        font-size: 22px;
    }
    
    .login-logo p {
        font-size: 13px;
    }
}

/* ============================================
   欢迎区块 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .dashboard-welcome {
        padding: 20px 15px;
        margin-bottom: 20px;
        border-radius: 16px;
    }
    
    .welcome-content {
        flex-direction: column;
        gap: 15px;
        text-align: center;
    }
    
    .welcome-text h2 {
        font-size: 22px;
        margin-bottom: 5px;
    }
    
    .welcome-text p {
        font-size: 14px;
    }
    
    .welcome-stats {
        width: 100%;
        justify-content: space-around;
        gap: 15px;
        flex-wrap: wrap;
    }
    
    .welcome-stat {
        flex: 1;
        min-width: 80px;
    }
    
    .welcome-stat-value {
        font-size: 24px;
    }
    
    .welcome-stat-label {
        font-size: 11px;
    }
}

/* ============================================
   仪表板布局 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .dashboard-layout {
        flex-direction: column;
        gap: 20px;
        margin-bottom: 30px;
    }
    
    .modules-section,
    .action-required-section {
        width: 100%;
    }
    
    /* 区块标题 */
    .section-header {
        margin-bottom: 15px;
    }
    
    .section-header h3 {
        font-size: 20px;
        margin-bottom: 3px;
    }
    
    .section-header p {
        font-size: 13px;
    }
}

/* ============================================
   模块卡片网格 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .modules-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        max-height: none;
        padding-right: 0;
    }
    
    .module-card {
        border-radius: 16px;
        min-height: 140px;
        aspect-ratio: auto;
    }
    
    .module-header-section {
        padding: 15px 10px;
    }
    
    .module-icon {
        width: 55px;
        height: 55px;
        border-radius: 14px;
        font-size: 28px;
        margin-bottom: 10px;
    }
    
    .module-icon i {
        font-size: 28px;
    }
    
    .module-card h4 {
        font-size: 13px;
        line-height: 1.2;
    }
    
    .module-badge {
        padding: 6px 12px;
        font-size: 10px;
    }
    
    /* 单列显示（小屏手机）*/
    @media (max-width: 480px) {
        .modules-grid {
            grid-template-columns: 1fr;
            gap: 10px;
        }
        
        .module-card {
            flex-direction: row;
            aspect-ratio: auto;
            min-height: 90px;
            padding: 12px;
        }
        
        .module-header-section {
            flex-direction: row;
            align-items: center;
            gap: 12px;
            padding: 0;
            text-align: left;
        }
        
        .module-icon {
            width: 50px;
            height: 50px;
            margin-bottom: 0;
            flex-shrink: 0;
        }
        
        .module-title-section {
            flex: 1;
        }
        
        .module-arrow {
            flex-shrink: 0;
        }
    }
}

/* ============================================
   待办事项区块 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .action-required-card {
        border-radius: 16px;
        max-height: 400px;
    }
    
    .action-items-container {
        padding: 15px;
    }
    
    .action-item {
        gap: 12px;
        padding: 15px;
        border-radius: 10px;
        margin-bottom: 12px;
    }
    
    .action-item-icon {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }
    
    .action-item-content h4 {
        font-size: 13px;
    }
    
    .action-item-content p {
        font-size: 11px;
        -webkit-line-clamp: 1;
    }
}

/* ============================================
   统计卡片 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .stats-section {
        margin-bottom: 30px;
    }
    
    .stats-grid {
        grid-template-columns: 1fr;
        gap: 15px;
    }
    
    .stat-card {
        padding: 20px;
        border-radius: 12px;
    }
    
    .stat-header {
        margin-bottom: 12px;
    }
    
    .stat-icon-wrapper {
        width: 45px;
        height: 45px;
        font-size: 22px;
    }
    
    .stat-label {
        font-size: 12px;
        margin-bottom: 6px;
    }
    
    .stat-value {
        font-size: 30px;
    }
    
    .stat-footer {
        font-size: 12px;
    }
}

/* ============================================
   活动区块 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .activity-section {
        padding: 20px 15px;
        margin-bottom: 30px;
        border-radius: 16px;
    }
    
    .activity-header {
        margin-bottom: 20px;
        flex-wrap: wrap;
    }
    
    .activity-header h3 {
        font-size: 20px;
    }
    
    .view-all-btn {
        font-size: 13px;
    }
    
    .activity-list {
        gap: 15px;
    }
    
    .activity-item {
        flex-direction: column;
        text-align: center;
        padding: 15px;
        gap: 12px;
    }
    
    .activity-icon {
        width: 45px;
        height: 45px;
    }
    
    .activity-title {
        font-size: 14px;
    }
    
    .activity-description {
        font-size: 12px;
    }
}

/* ============================================
   按钮 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .btn {
        padding: 10px 20px;
        font-size: 14px;
        width: 100%;
        justify-content: center;
    }
    
    .btn i {
        font-size: 14px;
    }
    
    .module-actions {
        flex-direction: column;
        gap: 10px;
    }
    
    .module-actions .btn {
        width: 100%;
    }
}

/* ============================================
   表单 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .form-group {
        margin-bottom: 15px;
    }
    
    label {
        font-size: 13px;
        margin-bottom: 6px;
    }
    
    input[type="text"],
    input[type="email"],
    input[type="password"],
    input[type="number"],
    input[type="tel"],
    input[type="date"],
    input[type="datetime-local"],
    input[type="week"],
    input[type="month"],
    select,
    textarea {
        padding: 10px 14px;
        font-size: 14px;
        border-radius: 8px;
    }
    
    textarea {
        min-height: 80px;
    }
    
    .alert {
        padding: 12px 15px;
        font-size: 13px;
        border-radius: 10px;
    }
}

/* ============================================
   模态框 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .modal {
        padding: 10px;
    }
    
    .modal-content {
        max-width: 95%;
        border-radius: 16px;
        max-height: 85vh;
    }
    
    .modal-header {
        padding: 20px;
        border-radius: 16px 16px 0 0;
    }
    
    .modal-header h2 {
        font-size: 18px;
    }
    
    .close {
        width: 32px;
        height: 32px;
        font-size: 28px;
    }
    
    .modal-body {
        padding: 20px;
        max-height: 50vh;
    }
    
    .modal-actions {
        flex-direction: column-reverse;
        gap: 10px;
        padding-top: 20px;
    }
    
    .modal-actions button {
        width: 100%;
        padding: 12px 20px;
    }
    
    /* Modal.css 样式的移动端优化 */
    .modal-container {
        width: 95%;
        max-width: none;
        border-radius: 16px;
    }
    
    .modal-header {
        padding: 20px;
    }
    
    .modal-icon {
        width: 45px;
        height: 45px;
        font-size: 22px;
    }
    
    .modal-title {
        font-size: 18px;
    }
    
    .modal-subtitle {
        font-size: 12px;
    }
    
    .modal-body {
        padding: 20px;
        max-height: 300px;
    }
    
    .modal-message {
        font-size: 14px;
    }
    
    .modal-footer {
        padding: 15px 20px;
        flex-direction: column-reverse;
    }
    
    .modal-btn {
        width: 100%;
        justify-content: center;
        padding: 12px 20px;
    }
}

/* ============================================
   表格 - 移动端卡片式布局
   ============================================ */
@media (max-width: 768px) {
    /* 取消横向滚动，改为卡片式布局 */
    .table-container {
        overflow-x: visible;
        border-radius: 0;
        background: transparent;
        box-shadow: none;
        border: none;
    }

    /* 隐藏表头 */
    table.paginated-table thead {
        display: none !important;
    }

    /* 整个 table 变成 block */
    table.paginated-table,
    table.paginated-table tbody {
        display: block;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* 每一行变成卡片 */
    table.paginated-table tbody tr {
        display: block;
        background: white;
        border: 1px solid #e5e7eb;
        border-radius: 12px;
        margin-bottom: 12px;
        padding: 0;
        box-shadow: 0 1px 4px rgba(0,0,0,0.06);
        overflow: hidden;
        max-width: 100%;
        box-sizing: border-box;
    }

    /* 每个 td 变成一行 label: value */
    table.paginated-table tbody td {
        display: flex;
        align-items: flex-start;
        justify-content: space-between;
        padding: 10px 15px;
        font-size: 13px;
        border: none;
        border-bottom: 1px solid #f3f4f6;
        min-height: 40px;
        gap: 10px;
        box-sizing: border-box;
        width: 100%;
        overflow: hidden;
    }

    table.paginated-table tbody td:last-child {
        border-bottom: none;
        background: #fafafa;
        border-radius: 0 0 12px 12px;
    }

    /* label 部分 (由 JS 注入 data-label) */
    table.paginated-table tbody td::before {
        content: attr(data-label);
        font-weight: 600;
        color: #6834ad;
        font-size: 12px;
        flex-shrink: 0;
        width: 110px;
        min-width: 110px;
        max-width: 110px;
        padding-top: 1px;
    }

    /* 隐藏没有 data-label 的 td 的 before（例如 action 列） */
    table.paginated-table tbody td[data-label=""]::before,
    table.paginated-table tbody td:not([data-label])::before {
        display: none;
    }

    /* value 部分 — 限制宽度并允许换行 */
    table.paginated-table tbody td > *,
    table.paginated-table tbody td .td-value {
        text-align: right;
        flex: 1;
        min-width: 0;              /* 允许 flex 子项缩小 */
        word-break: break-word;
        overflow-wrap: anywhere;
        white-space: normal;
    }

    /* 纯文字内容（没有子元素）也要换行 */
    table.paginated-table tbody td {
        word-break: break-word;
        overflow-wrap: anywhere;
    }

    /* Action 按钮列 - View 靠左, Edit 居中, Delete 靠右 */
    table.paginated-table tbody td:last-child {
        display: flex;
        justify-content: space-between;
        align-items: center;
        flex-wrap: nowrap;
        gap: 6px;
        padding: 10px 15px;
    }

    /* 每个 form 占据 1/3 宽度，按钮撑满 form */
    table.paginated-table tbody td:last-child form {
        display: flex;
        flex: 1;
        flex-wrap: nowrap;
    }

    /* View form 靠左 */
    table.paginated-table tbody td:last-child form:first-of-type {
        justify-content: flex-start;
    }

    /* Edit form 居中 */
    table.paginated-table tbody td:last-child form:nth-of-type(2) {
        justify-content: center;
    }

    /* Delete form 靠右 */
    table.paginated-table tbody td:last-child form:last-of-type {
        justify-content: flex-end;
    }

    /* 如果按钮直接放在 td 里（不包在 form 内） */
    table.paginated-table tbody td:last-child > button:first-of-type,
    table.paginated-table tbody td:last-child > a.btn:first-of-type {
        margin-right: auto;
    }

    table.paginated-table tbody td:last-child > button:last-of-type,
    table.paginated-table tbody td:last-child > a.btn:last-of-type {
        margin-left: auto;
    }

    table.paginated-table tbody td:last-child button,
    table.paginated-table tbody td:last-child a.btn {
        flex: none;
        white-space: nowrap;
        padding: 6px 14px !important;
        font-size: 12px !important;
        min-height: unset !important;
        width: auto !important;
    }

    /* 空结果行不变成卡片 */
    table.paginated-table tbody tr:has(.no-results) {
        border: none;
        box-shadow: none;
        background: transparent;
    }

    table.paginated-table tbody tr td[colspan] {
        display: block;
        border: none;
    }

    /* 兼容旧的 .table-responsive-cards 写法 */
    .table-responsive-cards table {
        min-width: 100%;
    }
}

/* ============================================
   标签页 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .tabs {
        overflow-x: auto;
        -webkit-overflow-scrolling: touch;
        gap: 5px;
        margin-bottom: 20px;
        scrollbar-width: none;
    }
    
    .tabs::-webkit-scrollbar {
        display: none;
    }
    
    .tab {
        padding: 10px 18px;
        font-size: 13px;
        white-space: nowrap;
        flex-shrink: 0;
    }
}

/* ============================================
   徽章 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .badge {
        padding: 5px 12px;
        font-size: 11px;
    }
}

/* ============================================
   时间线 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .timeline {
        padding-left: 30px;
    }
    
    .timeline::before {
        left: 10px;
    }
    
    .timeline-item::before {
        left: -24px;
        width: 10px;
        height: 10px;
    }
    
    .timeline-date {
        font-size: 11px;
    }
    
    .timeline-content {
        padding: 12px 15px;
    }
    
    .timeline-title {
        font-size: 13px;
    }
    
    .timeline-description {
        font-size: 12px;
    }
}

/* ============================================
   图片上传预览 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .upload-area {
        padding: 15px;
    }
    
    .upload-buttons {
        flex-direction: column;
        align-items: stretch;
    }
    
    .upload-buttons span {
        margin-left: 0 !important;
        margin-top: 10px;
        text-align: center;
    }
    
    .image-preview-container {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        margin-top: 12px;
    }
    
    .image-preview-item img {
        height: 120px;
    }
    
    .remove-image-btn {
        width: 26px;
        height: 26px;
        font-size: 18px;
    }
    
    .image-name {
        padding: 6px 8px;
        font-size: 10px;
    }
}

/* ============================================
   日历 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .calendar-grid {
        gap: 5px;
    }
    
    .calendar-day {
        padding: 10px 5px;
        font-size: 12px;
    }
    
    .calendar-day-header {
        font-size: 10px;
    }
}

/* ============================================
   模块页面 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .module-header {
        padding: 20px 15px;
        margin-bottom: 20px;
        border-radius: 16px;
    }
    
    .module-header h1 {
        font-size: 24px;
        margin-bottom: 8px;
    }
    
    .module-header h1 i {
        font-size: 22px;
    }
    
    .module-header p {
        font-size: 14px;
        margin-bottom: 20px;
    }
    
    .content-section {
        padding: 20px 15px;
        border-radius: 12px;
        margin-bottom: 20px;
    }
}

/* ============================================
   页脚 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .footer {
        padding: 20px 15px;
        font-size: 12px;
    }
}

/* ============================================
   触摸优化
   ============================================ */
@media (max-width: 768px) {
    /* 增加可点击区域 */
    a, button, .btn, .tab, .dropdown-item {
        min-height: 44px;
        display: inline-flex;
        align-items: center;
    }
    
    /* 触摸反馈 */
    .module-card:active,
    .action-item:active,
    .btn:active,
    .tab:active {
        opacity: 0.7;
        transform: scale(0.98);
    }
    
    /* 防止双击缩放 */
    input, textarea, select, button {
        touch-action: manipulation;
    }
}

/* ============================================
   横屏优化
   ============================================ */
@media (max-width: 768px) and (orientation: landscape) {
    .login-container {
        padding: 15px;
    }
    
    .login-box {
        max-width: 500px;
        padding: 25px 30px;
    }
    
    .dashboard-welcome {
        padding: 20px;
    }
    
    .welcome-content {
        flex-direction: row;
        text-align: left;
    }
    
    .modules-grid {
        grid-template-columns: repeat(3, 1fr);
    }
    
    .modal-content {
        max-height: 80vh;
    }
}

/* ============================================
   小屏手机额外优化 (iPhone SE等)
   ============================================ */
@media (max-width: 375px) {
    .container {
        padding: 0 10px;
    }
    
    .logo-text h1 {
        font-size: 16px;
    }
    
    .welcome-text h2 {
        font-size: 20px;
    }
    
    .section-header h3 {
        font-size: 18px;
    }
    
    .module-icon {
        width: 50px;
        height: 50px;
        font-size: 26px;
    }
    
    .module-card h4 {
        font-size: 12px;
    }
    
    .stat-value {
        font-size: 26px;
    }
}

/* ============================================
   状态切换开关 - 移动端优化
   ============================================ */
@media (max-width: 768px) {
    .status-row {
        flex-direction: column;
        align-items: flex-start;
        gap: 12px;
    }
    
    .status-left {
        width: 100%;
    }
    
    .status-right {
        width: 100%;
        justify-content: space-between;
    }
    
    .toggle-switch {
        width: 50px;
        height: 24px;
    }
}

/* ============================================
   加载动画 - 移动端
   ============================================ */
@media (max-width: 768px) {
    .loading-spinner {
        width: 40px;
        height: 40px;
    }
}

/* ============================================
   工具提示 - 移动端禁用
   ============================================ */
@media (max-width: 768px) {
    .tooltip {
        display: none !important;
    }
}

/* ============================================
   移动端二级子菜单 (Sub-Group) 样式
   用于 Modules → Staff Management → View Staff
   ============================================ */

/* Sub-group 容器 */
.mobile-sub-group {
    border-bottom: 1px solid rgba(104, 52, 173, 0.08);
}

.mobile-sub-group:last-child {
    border-bottom: none;
}

/* Sub-group 触发器 (e.g. "Staff Management") */
.mobile-sub-group-trigger {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px 12px 20px;
    cursor: pointer;
    transition: background 0.2s ease;
    user-select: none;
    -webkit-user-select: none;
}

.mobile-sub-group-trigger:hover,
.mobile-sub-group.expanded > .mobile-sub-group-trigger {
    background: linear-gradient(135deg, rgba(104, 52, 173, 0.08) 0%, rgba(139, 92, 246, 0.08) 100%);
}

.mobile-sub-group-trigger-content {
    display: flex;
    align-items: center;
    gap: 10px;
    color: #374151;
    font-size: 13.5px;
    font-weight: 600;
}

.mobile-sub-group-trigger-content i {
    font-size: 15px;
    width: 20px;
    text-align: center;
    color: #6834ad;
}

.mobile-sub-group.expanded > .mobile-sub-group-trigger .mobile-sub-group-trigger-content {
    color: #6834ad;
}

/* 箭头图标旋转动画 */
.mobile-sub-group-arrow {
    font-size: 11px;
    color: #9ca3af;
    transition: transform 0.25s ease, color 0.2s ease;
    flex-shrink: 0;
}

.mobile-sub-group.expanded > .mobile-sub-group-trigger .mobile-sub-group-arrow {
    transform: rotate(90deg);
    color: #6834ad;
}

/* Sub-submenu 容器（收起状态） */
.mobile-sub-submenu {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease;
    background: rgba(249, 250, 251, 0.8);
}

/* Sub-submenu 展开状态 */
.mobile-sub-group.expanded > .mobile-sub-submenu {
    max-height: 900px;
}

/* Sub-submenu 里面的每一个链接 */
.mobile-sub-submenu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px 10px 44px;
    color: #4b5563;
    text-decoration: none;
    font-size: 13px;
    font-weight: 500;
    border-bottom: 1px solid rgba(229, 231, 235, 0.5);
    transition: background 0.2s ease, color 0.2s ease;
    min-height: 40px;
}

.mobile-sub-submenu-item:last-child {
    border-bottom: none;
}

.mobile-sub-submenu-item:hover {
    background: linear-gradient(135deg, rgba(104, 52, 173, 0.06) 0%, rgba(139, 92, 246, 0.06) 100%);
    color: #6834ad;
}

.mobile-sub-submenu-item i {
    font-size: 13px;
    width: 16px;
    text-align: center;
    color: #9ca3af;
    flex-shrink: 0;
}

.mobile-sub-submenu-item:hover i {
    color: #8b5cf6;
}

/* ============================================
   打印样式优化
   ============================================ */
@media print {
    .header,
    .module-actions,
    .btn,
    .logout-btn,
    .settings-dropdown,
    .footer {
        display: none !important;
    }
    
    body {
        background: white !important;
    }
    
    .container {
        max-width: 100%;
        margin: 0;
        padding: 0;
    }
}

/* ============================================
   可访问性增强
   ============================================ */
@media (max-width: 768px) {
    /* 焦点指示器 */
    *:focus-visible {
        outline: 3px solid #6834ad;
        outline-offset: 2px;
    }
    
    /* 高对比度模式支持 */
    @media (prefers-contrast: high) {
        .btn, .badge, .module-card {
            border: 2px solid currentColor;
        }
    }
    
    /* 减少动画模式 */
    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.01ms !important;
        }
    }
}
