/**
 * Default Theme - TDesign
 * 基于 TDesign 设计规范的自定义主题样式
 */

/* ========== CSS 变量定义 ========== */
:root {
    /* 品牌色 */
    --theme-primary: #0052d9;
    --theme-primary-hover: #0034b5;
    --theme-primary-active: #002a9c;
    --theme-primary-light: #ecf2fe;
    --theme-primary-light-hover: #d9e1ff;

    /* 功能色 */
    --theme-success: #2ba471;
    --theme-warning: #e37318;
    --theme-error: #d54941;
    --theme-info: #0052d9;

    /* 文字色 */
    --theme-text-primary: #1a1a1a;
    --theme-text-secondary: #4b4b4b;
    --theme-text-placeholder: #a6a6a6;
    --theme-text-disabled: #c5c5c5;
    --theme-text-white: #ffffff;

    /* 背景色 */
    --theme-bg-page: #f3f3f3;
    --theme-bg-container: #ffffff;
    --theme-bg-container-hover: #f9f9f9;
    --theme-bg-container-active: #eeeeee;

    /* 边框色 */
    --theme-border: #dcdcdc;
    --theme-border-light: #e7e7e7;

    /* 圆角 */
    --theme-radius-sm: 3px;
    --theme-radius-md: 6px;
    --theme-radius-lg: 9px;
    --theme-radius-round: 999px;

    /* 间距 */
    --theme-space-xs: 4px;
    --theme-space-sm: 8px;
    --theme-space-md: 16px;
    --theme-space-lg: 24px;
    --theme-space-xl: 32px;
    --theme-space-xxl: 48px;

    /* 字体 */
    --theme-font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    --theme-font-size-xs: 12px;
    --theme-font-size-sm: 13px;
    --theme-font-size-base: 14px;
    --theme-font-size-lg: 16px;
    --theme-font-size-xl: 20px;
    --theme-font-size-xxl: 24px;

    /* 行高 */
    --theme-line-height-sm: 1.3;
    --theme-line-height-base: 1.5;
    --theme-line-height-lg: 1.8;

    /* 阴影 */
    --theme-shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.06);
    --theme-shadow-md: 0 2px 8px rgba(0, 0, 0, 0.08);
    --theme-shadow-lg: 0 4px 16px rgba(0, 0, 0, 0.1);

    /* 过渡 */
    --theme-transition: 0.2s ease;

    /* 布局 */
    --theme-header-height: 56px;
    --theme-sidebar-width: 220px;
    --theme-sidebar-collapsed-width: 60px;
    --theme-content-max-width: 1200px;
    --theme-footer-height: auto;
}

/* ========== 基础重置 ========== */
*,
*::before,
*::after {
    box-sizing: border-box;
}

html {
    font-size: var(--theme-font-size-base);
    line-height: var(--theme-line-height-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    padding: 0;
    font-family: var(--theme-font-family);
    font-size: var(--theme-font-size-base);
    color: var(--theme-text-primary);
    background-color: var(--theme-bg-page);
}

a {
    color: var(--theme-primary);
    text-decoration: none;
    transition: color var(--theme-transition);
}

a:hover {
    color: var(--theme-primary-hover);
}

/* ========== 布局容器 ========== */
.layout-container {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* ========== 顶部导航栏 ========== */
.layout-header {
    height: var(--theme-header-height);
    background-color: var(--theme-bg-container);
    border-bottom: 1px solid var(--theme-border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--theme-space-lg);
    position: sticky;
    top: 0;
    z-index: 1000;
    box-shadow: var(--theme-shadow-sm);
    flex-shrink: 0;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--theme-space-md);
}

.header-logo {
    display: flex;
    align-items: center;
    gap: var(--theme-space-sm);
    cursor: pointer;
    user-select: none;
    flex-shrink: 0;
}

.header-logo .logo-img {
    height: 28px;
    width: auto;
}

.header-logo .logo-title {
    font-size: var(--theme-font-size-lg);
    font-weight: 600;
    color: var(--theme-text-primary);
    white-space: nowrap;
}

.sidebar-toggle-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border-radius: var(--theme-radius-md);
    cursor: pointer;
    color: var(--theme-text-secondary);
    transition: all var(--theme-transition);
}

.sidebar-toggle-btn:hover {
    background-color: var(--theme-bg-container-hover);
    color: var(--theme-primary);
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--theme-space-md);
}

.header-balance {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background-color: var(--theme-primary-light);
    color: var(--theme-primary);
    border-radius: var(--theme-radius-round);
    font-size: var(--theme-font-size-sm);
    font-weight: 500;
    cursor: pointer;
    transition: all var(--theme-transition);
    white-space: nowrap;
}

.header-balance:hover {
    background-color: var(--theme-primary-light-hover);
}

.header-icon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--theme-radius-md);
    cursor: pointer;
    color: var(--theme-text-secondary);
    transition: all var(--theme-transition);
}

.header-icon-btn:hover {
    background-color: var(--theme-bg-container-hover);
    color: var(--theme-primary);
}

.header-user {
    display: flex;
    align-items: center;
    gap: var(--theme-space-sm);
    cursor: pointer;
    padding: 4px 8px;
    border-radius: var(--theme-radius-md);
    transition: all var(--theme-transition);
}

.header-user:hover {
    background-color: var(--theme-bg-container-hover);
}

.user-avatar-circle {
    background-color: var(--theme-primary);
    color: var(--theme-text-white);
    font-size: var(--theme-font-size-sm);
    font-weight: 500;
}

.user-name-text {
    font-size: var(--theme-font-size-base);
    color: var(--theme-text-primary);
    max-width: 100px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.mobile-menu-trigger {
    display: none;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: var(--theme-radius-md);
    cursor: pointer;
    color: var(--theme-text-secondary);
}

/* ========== 移动端遮罩 ========== */
.mobile-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.4);
    z-index: 1001;
    opacity: 0;
    transition: opacity 0.3s;
}

.mobile-overlay.visible {
    opacity: 1;
}

.mobile-sidebar-header {
    display: none;
    align-items: center;
    justify-content: space-between;
    padding: var(--theme-space-md) var(--theme-space-lg);
    font-size: var(--theme-font-size-lg);
    font-weight: 500;
    color: var(--theme-text-primary);
    border-bottom: 1px solid var(--theme-border-light);
}

/* ========== 主体区域 ========== */
.layout-body {
    flex: 1;
    display: flex;
    min-height: 0;
}

/* ========== 左侧菜单 ========== */
.layout-sidebar {
    width: var(--theme-sidebar-width);
    background-color: var(--theme-bg-container);
    border-right: 1px solid var(--theme-border-light);
    overflow-y: auto;
    overflow-x: hidden;
    flex-shrink: 0;
    transition: width 0.2s ease;
    position: sticky;
    top: var(--theme-header-height);
    height: calc(100vh - var(--theme-header-height));
}

.layout-sidebar.collapsed {
    width: var(--theme-sidebar-collapsed-width);
}

.sidebar-menu-wrap {
    border-right: none;
    padding-top: var(--theme-space-sm);
}

/* TDesign 菜单样式覆盖 */
.sidebar-menu-wrap.t-menu {
    border-right: none;
}

.sidebar-menu-wrap .t-menu-item,
.sidebar-menu-wrap .t-submenu .t-menu-item {
    border-radius: var(--theme-radius-md);
    margin: 2px 8px;
    height: 40px;
    line-height: 40px;
}

.sidebar-menu-wrap .t-submenu__title {
    border-radius: var(--theme-radius-md);
    margin: 2px 8px;
    height: 40px;
    line-height: 40px;
}

.sidebar-menu-wrap .t-menu-item:hover,
.sidebar-menu-wrap .t-submenu__title:hover {
    background-color: var(--theme-bg-container-hover);
}

.sidebar-menu-wrap .t-menu-item.t-is-active {
    color: var(--theme-primary);
    background-color: var(--theme-primary-light);
}

/* ========== 内容区域 ========== */
.layout-content {
    flex: 1;
    padding: var(--theme-space-lg);
    overflow-x: hidden;
    min-width: 0;
    background-color: var(--theme-bg-page);
}

/* ========== 页脚 ========== */
.layout-footer {
    padding: var(--theme-space-md) var(--theme-space-lg);
    text-align: center;
    color: var(--theme-text-placeholder);
    font-size: var(--theme-font-size-xs);
    border-top: 1px solid var(--theme-border-light);
    background-color: var(--theme-bg-container);
    flex-shrink: 0;
}

.layout-footer .footer-line {
    line-height: 1.8;
}

.layout-footer .footer-line a {
    color: var(--theme-text-placeholder);
}

.layout-footer .footer-line a:hover {
    color: var(--theme-primary);
}

/* ========== 通用页面组件 ========== */
.page-header {
    height: var(--theme-header-height);
    background-color: var(--theme-bg-container);
    border-bottom: 1px solid var(--theme-border-light);
    display: flex;
    align-items: center;
    padding: 0 var(--theme-space-lg);
}

.page-header .logo {
    display: flex;
    align-items: center;
    gap: var(--theme-space-sm);
    font-size: var(--theme-font-size-lg);
    font-weight: 600;
    color: var(--theme-text-primary);
}

.page-header .logo img {
    height: 28px;
    width: auto;
}

.page-header .nav {
    display: flex;
    align-items: center;
    gap: var(--theme-space-xs);
    margin-left: var(--theme-space-xl);
}

.page-header .nav-item {
    padding: var(--theme-space-sm) var(--theme-space-md);
    color: var(--theme-text-secondary);
    border-radius: var(--theme-radius-md);
    transition: all var(--theme-transition);
    font-size: var(--theme-font-size-base);
}

.page-header .nav-item:hover {
    color: var(--theme-primary);
    background-color: var(--theme-primary-light);
}

.page-header .nav-item.active {
    color: var(--theme-primary);
    font-weight: 500;
}

.page-header .header-right {
    margin-left: auto;
    display: flex;
    align-items: center;
    gap: var(--theme-space-md);
}

.page-body {
    flex: 1;
    display: flex;
}

.page-sidebar {
    width: var(--theme-sidebar-width);
    background-color: var(--theme-bg-container);
    border-right: 1px solid var(--theme-border-light);
    overflow-y: auto;
    flex-shrink: 0;
}

.page-content {
    flex: 1;
    padding: var(--theme-space-lg);
    overflow-x: hidden;
}

.page-footer {
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--theme-text-placeholder);
    font-size: var(--theme-font-size-xs);
    border-top: 1px solid var(--theme-border-light);
    background-color: var(--theme-bg-container);
    padding: var(--theme-space-md);
}

/* ========== 内容卡片 ========== */
.content-card {
    background-color: var(--theme-bg-container);
    border-radius: var(--theme-radius-lg);
    padding: var(--theme-space-lg);
    margin-bottom: var(--theme-space-md);
    box-shadow: var(--theme-shadow-sm);
}

.content-card .card-title {
    font-size: var(--theme-font-size-lg);
    font-weight: 600;
    color: var(--theme-text-primary);
    margin: 0 0 var(--theme-space-md) 0;
    padding-bottom: var(--theme-space-md);
    border-bottom: 1px solid var(--theme-border-light);
}

.content-card .card-body {
    color: var(--theme-text-secondary);
}

/* ========== 页面标题栏 ========== */
.page-title-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--theme-space-lg);
}

.page-title-bar h1 {
    font-size: var(--theme-font-size-xl);
    font-weight: 600;
    color: var(--theme-text-primary);
    margin: 0;
}

.page-title-bar .breadcrumb {
    display: flex;
    align-items: center;
    gap: var(--theme-space-xs);
    font-size: var(--theme-font-size-sm);
    color: var(--theme-text-placeholder);
}

.page-title-bar .breadcrumb a {
    color: var(--theme-text-secondary);
}

.page-title-bar .breadcrumb a:hover {
    color: var(--theme-primary);
}

/* ========== 表格工具栏 ========== */
.table-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: var(--theme-space-md);
    flex-wrap: wrap;
    gap: var(--theme-space-sm);
}

.table-toolbar .toolbar-left {
    display: flex;
    align-items: center;
    gap: var(--theme-space-sm);
}

.table-toolbar .toolbar-right {
    display: flex;
    align-items: center;
    gap: var(--theme-space-sm);
}

/* ========== 状态标签 ========== */
.status-tag {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    border-radius: var(--theme-radius-round);
    font-size: var(--theme-font-size-xs);
    line-height: 1.6;
}

.status-tag--success {
    color: var(--theme-success);
    background-color: #e8f8f0;
}

.status-tag--warning {
    color: var(--theme-warning);
    background-color: #fef3e6;
}

.status-tag--error {
    color: var(--theme-error);
    background-color: #fde8e8;
}

.status-tag--info {
    color: var(--theme-info);
    background-color: var(--theme-primary-light);
}

.status-tag--default {
    color: var(--theme-text-secondary);
    background-color: var(--theme-bg-container-active);
}

/* ========== 统计卡片 ========== */
.stat-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--theme-space-md);
    margin-bottom: var(--theme-space-lg);
}

.stat-card {
    background-color: var(--theme-bg-container);
    border-radius: var(--theme-radius-lg);
    padding: var(--theme-space-lg);
    box-shadow: var(--theme-shadow-sm);
}

.stat-card .stat-label {
    font-size: var(--theme-font-size-sm);
    color: var(--theme-text-placeholder);
    margin-bottom: var(--theme-space-sm);
}

.stat-card .stat-value {
    font-size: var(--theme-font-size-xxl);
    font-weight: 600;
    color: var(--theme-text-primary);
}

.stat-card .stat-trend {
    font-size: var(--theme-font-size-xs);
    margin-top: var(--theme-space-xs);
}

.stat-card .stat-trend--up {
    color: var(--theme-success);
}

.stat-card .stat-trend--down {
    color: var(--theme-error);
}

/* ========== 空状态 ========== */
.empty-state {
    text-align: center;
    padding: var(--theme-space-xxl) var(--theme-space-lg);
    color: var(--theme-text-placeholder);
}

.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: var(--theme-space-md);
    opacity: 0.4;
}

.empty-state .empty-text {
    font-size: var(--theme-font-size-base);
    margin-bottom: var(--theme-space-md);
}

/* ========== TDesign 组件覆盖 ========== */

/* 下拉菜单项图标对齐 */
.t-dropdown__item .t-icon {
    vertical-align: middle;
}

/* Badge 在导航栏中的样式 */
.header-icon-btn .t-badge {
    display: flex;
}

/* ========== 响应式设计 ========== */
@media (max-width: 1024px) {
    .layout-sidebar {
        width: var(--theme-sidebar-collapsed-width);
    }
    .layout-sidebar.collapsed {
        width: var(--theme-sidebar-collapsed-width);
    }
}

@media (max-width: 768px) {
    /* 顶部栏调整 */
    .header-balance {
        display: none;
    }
    .user-name-text {
        display: none;
    }
    .sidebar-toggle-btn {
        display: none;
    }
    .mobile-menu-trigger {
        display: flex;
    }

    /* 侧边栏变为抽屉 */
    .layout-sidebar {
        position: fixed;
        top: 0;
        left: 0;
        height: 100vh;
        width: 260px;
        z-index: 1002;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        box-shadow: none;
    }
    .layout-sidebar.collapsed {
        width: 260px;
        transform: translateX(-100%);
    }
    .layout-sidebar.mobile-open {
        transform: translateX(0);
        box-shadow: var(--theme-shadow-lg);
    }
    .mobile-overlay {
        display: block;
    }
    .mobile-overlay:not(.visible) {
        pointer-events: none;
    }
    .mobile-sidebar-header {
        display: flex;
    }

    /* 内容区域 */
    .layout-content {
        padding: var(--theme-space-md);
    }

    .stat-cards {
        grid-template-columns: repeat(2, 1fr);
    }

    .table-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .page-header .nav {
        display: none;
    }
    .page-sidebar {
        display: none;
    }
    .page-content {
        padding: var(--theme-space-md);
    }
}

@media (max-width: 480px) {
    .stat-cards {
        grid-template-columns: 1fr;
    }

    .content-card {
        padding: var(--theme-space-md);
    }

    .layout-header {
        padding: 0 var(--theme-space-md);
    }
}
