/* ===== 全局样式 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }
:root {
    --primary: #4f46e5;
    --primary-dark: #4338ca;
    --primary-soft: #eef2ff;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #0f172a;
    /* 新: 白色侧边栏 */
    --sidebar-bg: #ffffff;
    --sidebar-hover: #f1f5f9;
    --sidebar-active-bg: #eef2ff;
    --sidebar-active-text: #4f46e5;
    --sidebar-border: #f1f5f9;
    --sidebar-text: #475569;
    --sidebar-text-muted: #94a3b8;
}
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
    background: var(--gray-100);
    color: var(--gray-900);
    font-size: 14px;
}

/* ===== 登录页 ===== */
.login-body {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}
.login-container { width: 100%; max-width: 420px; padding: 20px; }
.login-card {
    background: #fff;
    border-radius: 16px;
    padding: 40px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.login-header { text-align: center; margin-bottom: 30px; }
.login-logo { font-size: 56px; margin-bottom: 10px; }
.login-header h1 { font-size: 24px; color: var(--gray-900); margin-bottom: 8px; }
.login-header p { color: var(--gray-500); font-size: 13px; }
.login-footer { text-align: center; margin-top: 20px; }
.login-footer a { color: var(--primary); text-decoration: none; font-size: 13px; }
.login-footer a:hover { text-decoration: underline; }

/* ===== 表单 ===== */
.form-group { margin-bottom: 20px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--gray-700); font-size: 13px; }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--gray-300);
    border-radius: 8px; font-size: 14px; transition: border-color 0.2s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79,70,229,0.1);
}
.error-msg { color: var(--danger); font-size: 13px; margin-top: 10px; min-height: 18px; }
.success-msg { color: var(--success); font-size: 13px; margin-top: 10px; }

/* ===== 按钮 ===== */
.btn {
    display: inline-flex; align-items: center; justify-content: center;
    padding: 8px 16px; border: none; border-radius: 8px; font-size: 14px;
    cursor: pointer; transition: all 0.2s; text-decoration: none; gap: 6px;
}
.btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-default { background: var(--gray-200); color: var(--gray-700); }
.btn-default:hover { background: var(--gray-300); }
.btn-block { width: 100%; padding: 12px; font-size: 15px; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

/* ===== 布局 ===== */
.layout { display: flex; min-height: 100vh; background: #f8fafc; }

/* 侧边栏 - 白底彩色图标 */
.sidebar {
    width: 230px; background: #fff;
    position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
    transition: transform 0.3s; overflow-y: auto;
    border-right: 1px solid #f1f5f9;
}
.sidebar-header { padding: 20px 20px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid #f1f5f9; }
.sidebar-logo img { border-radius: 10px; width: 42px; height: 42px; }
.sidebar-title { font-size: 18px; font-weight: 800; color: #0f172a; letter-spacing: -0.3px; }
.sidebar-nav { padding: 8px 12px 24px; }

/* 菜单项 */
.nav-item {
    display: flex; align-items: center; gap: 12px; padding: 10px 12px;
    color: #64748b; text-decoration: none; transition: all .15s; font-size: 13.5px;
    border-radius: 10px; font-weight: 500; margin-bottom: 2px;
}
.nav-item:hover { background: #f8fafc; color: #0f172a; }
.nav-item.active {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
    color: #fff; box-shadow: 0 2px 8px rgba(99,102,241,.25);
}
.nav-item.active .nav-icon { filter: brightness(0) invert(1); }
.nav-icon { font-size: 18px; width: 20px; text-align: center; flex-shrink: 0; }

/* 菜单分组 */
.nav-group { margin-top: 4px; }
.nav-group-title {
    padding: 10px 12px 8px; font-size: 13.5px; color: #475569;
    cursor: pointer; display: flex; justify-content: space-between; align-items: center;
    user-select: none; font-weight: 500;
}
.nav-group-title:hover { color: #64748b; }
.nav-group-arrow { font-size: 13px; transition: transform .2s ease; color: #cbd5e1; font-weight: 700; }
.nav-group.collapsed .nav-group-arrow { transform: rotate(-90deg); }
.nav-group-items { overflow: hidden; transition: max-height .3s ease; max-height: 2000px; }
.nav-group.collapsed .nav-group-items { max-height: 0; }
.nav-group .nav-item { padding-left: 12px; font-size: 13px; }

/* 主内容区 */
.main-content { flex: 1; margin-left: 230px; display: flex; flex-direction: column; min-height: 100vh; }

/* 顶部栏 */
.topbar {
    height: 56px; background: #fff; border-bottom: 1px solid #f1f5f9;
    display: flex; align-items: center; padding: 0 24px; gap: 16px;
    position: sticky; top: 0; z-index: 50;
}
.menu-toggle { display: none; background: none; border: none; font-size: 20px; cursor: pointer; color: #64748b; }
.topbar-tabs { flex: 1; display: flex; align-items: center; gap: 0; overflow-x: auto; overflow-y: hidden; height: 100%; padding: 6px 0; }
.topbar-tabs::-webkit-scrollbar { height: 0; }
.tab-item { display: inline-flex; align-items: center; gap: 4px; padding: 6px 12px; font-size: 13px; color: #64748b; background: #f8fafc; border: 1px solid #e2e8f0; border-bottom: none; border-radius: 4px 4px 0 0; cursor: pointer; white-space: nowrap; transition: all .15s; margin-right: 2px; height: 38px; line-height: 1; position: relative; top: 1px; }
.tab-item:hover { color: #334155; background: #f1f5f9; }
.tab-item.active { color: #4f46e5; background: #fff; border-color: #e2e8f0; border-bottom: 2px solid #4f46e5; font-weight: 600; }
.tab-item .tab-close { width: 18px; height: 18px; border-radius: 50%; display: inline-flex; align-items: center; justify-content: center; font-size: 14px; color: #94a3b8; margin-left: 4px; transition: all .15s; cursor: pointer; line-height: 1; flex-shrink: 0; }
.tab-item .tab-close:hover { background: #ef4444; color: #fff; }
.tab-item.active .tab-close:hover { background: #ef4444; color: #fff; }
.tab-home { color: #10b981; }
.tab-home.active { color: #059669; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.tenant-badge { background: #f1f5f9; padding: 5px 12px; border-radius: 20px; font-size: 12px; color: #475569; font-weight: 500; }
.user-info { font-size: 13px; color: #475569; font-weight: 500; }

/* 页面内容 */
.page-content { padding: 24px; flex: 1; max-width: 100%; }

/* ===== 卡片 ===== */
.card { background: #fff; border-radius: 14px; box-shadow: 0 1px 3px rgba(15,23,42,.06); padding: 22px; margin-bottom: 20px; border: 1px solid #f1f5f9; }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 16px; }
.card-title { font-size: 15px; font-weight: 700; color: #0f172a; }

/* 统计卡片 - 多彩渐变 */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 16px; margin-bottom: 20px; }
.stat-card { background: #fff; border-radius: 14px; padding: 20px; border: 1px solid #f1f5f9; transition: all .2s; }
.stat-card:hover { transform: translateY(-2px); box-shadow: 0 6px 20px rgba(15,23,42,.08); }
.stat-card .stat-icon {
    width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
    font-size: 22px; margin-bottom: 14px;
}
.stat-card .stat-label { color: #94a3b8; font-size: 13px; margin-bottom: 6px; font-weight: 500; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; color: #0f172a; letter-spacing: -0.5px; }
.stat-card .stat-trend { font-size: 12px; margin-top: 10px; }
.stat-trend.up { color: var(--success); }
.stat-trend.down { color: var(--danger); }

/* Dashboard Banner */
.dash-banner {
    border-radius: 18px; padding: 36px 40px; margin-bottom: 20px;
    background: linear-gradient(135deg, #667eea 0%, #764ba2 50%, #f093fb 100%);
    color: #fff; position: relative; overflow: hidden; min-height: 180px;
    display: flex; align-items: center;
}
.dash-banner::before {
    content: ''; position: absolute; right: -60px; top: -60px; width: 300px; height: 300px;
    background: radial-gradient(circle, rgba(255,255,255,.15), transparent 70%);
    border-radius: 50%;
}
.dash-banner::after {
    content: ''; position: absolute; left: 40%; bottom: -80px; width: 200px; height: 200px;
    background: radial-gradient(circle, rgba(255,255,255,.1), transparent 70%);
    border-radius: 50%;
}
.dash-banner h2 { font-size: 32px; font-weight: 700; margin-bottom: 10px; letter-spacing: -0.5px; }
.dash-banner p { font-size: 15px; opacity: .9; margin: 0; }

/* 功能入口网格 */
.func-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 16px; padding: 4px 0; }
.func-item { text-align: center; cursor: pointer; transition: all .2s; padding: 6px 4px; border-radius: 12px; }
.func-item:hover { background: #f8fafc; transform: translateY(-2px); }
.func-ico {
    width: 52px; height: 52px; border-radius: 14px; display: flex; align-items: center; justify-content: center;
    font-size: 26px; margin: 0 auto 10px; position: relative;
}
.func-ico span { position: relative; z-index: 2; }
.func-ico::after { content:''; position:absolute; inset:0; border-radius:inherit; opacity:.15; }
.func-item .func-label { font-size: 12.5px; color: #475569; font-weight: 500; }

/* ===== 表格 ===== */
.table-container { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
table th, table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--gray-200); font-size: 14px; }
table th { background: var(--gray-50); font-weight: 600; color: var(--gray-700); white-space: nowrap; }
table tr:hover { background: var(--gray-50); }
.table-actions { display: flex; gap: 8px; }

/* 状态标签 */
.tag { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; }
.tag-success { background: #d1fae5; color: #065f46; }
.tag-warning { background: #fef3c7; color: #92400e; }
.tag-danger { background: #fee2e2; color: #991b1b; }
.tag-info { background: #dbeafe; color: #1e40af; }
.tag-default { background: var(--gray-100); color: var(--gray-700); }

/* ===== 模态框 ===== */
.modal-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 200; align-items: center; justify-content: center;
}
.modal-overlay.active { display: flex; }
.modal { background: #fff; border-radius: 12px; width: 90%; max-width: 1000px; max-height: 92vh; overflow: hidden; display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 16px 24px; border-bottom: 1px solid var(--gray-200); flex-shrink: 0; }
.modal-header h3 { font-size: 18px; margin: 0; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--gray-500); }
.modal-body { padding: 20px 24px; overflow-y: auto; overflow-x: auto; }

/* ===== Toast 轻提示 ===== */
.toast-fixed { position: fixed; top: 24px; left: 50%; transform: translateX(-50%) translateY(-20px); padding: 12px 24px; border-radius: 8px; color: #fff; font-size: 14px; z-index: 2000; opacity: 0; transition: all 0.25s ease; pointer-events: none; box-shadow: 0 4px 16px rgba(0,0,0,0.15); }
.toast-fixed.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast-fixed.success { background: #22c55e; }
.toast-fixed.error   { background: #ef4444; }
.toast-fixed.info    { background: #3b82f6; }

/* ===== 工具类 ===== */
.loading { text-align: center; padding: 40px; color: var(--gray-500); }
.empty { text-align: center; padding: 40px; color: var(--gray-500); }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-8 { gap: 8px; }
.gap-16 { gap: 16px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-16 { margin-bottom: 16px; }
.text-center { text-align: center; }
.text-sm { font-size: 12px; }
.text-gray { color: var(--gray-500); }

/* 聊天界面 */
.chat-container { display: flex; flex-direction: column; height: calc(100vh - 140px); }
.chat-messages { flex: 1; overflow-y: auto; padding: 20px; background: var(--gray-50); border-radius: 8px; margin-bottom: 16px; }
.chat-message { margin-bottom: 16px; }
.chat-message.user { text-align: right; }
.chat-message .bubble { display: inline-block; max-width: 70%; padding: 10px 14px; border-radius: 12px; text-align: left; }
.chat-message.user .bubble { background: var(--primary); color: #fff; }
.chat-message.assistant .bubble { background: #fff; border: 1px solid var(--gray-200); }
.chat-input { display: flex; gap: 12px; }
.chat-input input { flex: 1; padding: 12px; border: 1px solid var(--gray-300); border-radius: 8px; }

/* 分页 */
.pagination { display: flex; gap: 8px; justify-content: center; margin-top: 20px; align-items: center; }
.pagination button { min-width: 32px; height: 32px; }

/* 响应式 */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        box-shadow: 0 0 0 rgba(0,0,0,0);
        transition: transform .25s ease, box-shadow .25s ease;
    }
    .sidebar.open {
        transform: translateX(0);
        box-shadow: 4px 0 24px rgba(0,0,0,.15);
    }
    .main-content { margin-left: 0; }
    .menu-toggle { display: block; }
}
    .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* 菜单字典拖拽排序 */
.menu-sort-group {
    border: 1px solid var(--gray-200);
    border-radius: 10px;
    margin-bottom: 20px;
    overflow: hidden;
}
.menu-sort-group-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    background: linear-gradient(135deg, #f8fafc, #eef2f7);
    border-bottom: 1px solid var(--gray-200);
    font-weight: 600;
    font-size: 14px;
}
.menu-sort-group-title {
    display: flex;
    align-items: center;
    gap: 8px;
}
.menu-sort-group-title .icon { font-size: 18px; }
.menu-sort-group-count {
    color: var(--gray-500);
    font-weight: 400;
    font-size: 12px;
}
.menu-sort-list {
    list-style: none;
    padding: 8px;
    min-height: 40px;
}
.menu-sort-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    margin-bottom: 6px;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    cursor: grab;
    transition: box-shadow 0.15s, border-color 0.15s, transform 0.1s;
    user-select: none;
}
.menu-sort-item:hover {
    border-color: var(--primary);
    box-shadow: 0 2px 8px rgba(79, 70, 229, 0.1);
}
.menu-sort-item.sortable-dragging {
    opacity: 0.5;
    transform: rotate(2deg);
}
.menu-sort-item.sortable-ghost {
    opacity: 0.4;
    background: #f0f4ff;
    border-color: var(--primary);
}
.menu-sort-item.sortable-chosen {
    cursor: grabbing;
}
.sortable-fallback {
    position: fixed !important;
    z-index: 100000;
    opacity: 0.9;
    pointer-events: none;
    transform: rotate(2deg) scale(1.02);
    box-shadow: 0 8px 24px rgba(79, 70, 229, 0.25);
    background: #fff !important;
    border: 1px solid #6366f1 !important;
}
.menu-sort-handle {
    color: var(--gray-400);
    font-size: 18px;
    cursor: grab;
    flex-shrink: 0;
    padding: 4px 6px;
    border-radius: 4px;
    transition: background 0.15s, color 0.15s;
    user-select: none;
}
.menu-sort-handle:hover {
    background: var(--gray-200);
    color: var(--primary);
}
.menu-sort-item[draggable="true"] {
    cursor: grab;
}
.menu-sort-item[draggable="true"]:hover {
    background: #f8f9ff;
}
.menu-sort-item.sortable-chosen {
    cursor: grabbing;
    opacity: 0.7;
}
.menu-sort-item.sortable-ghost {
    border-top: 3px solid var(--primary) !important;
    position: relative;
}
.menu-sort-item.sortable-ghost::before {
    content: '';
    position: absolute;
    top: -3px;
    left: 20px;
    right: 20px;
    height: 3px;
    background: var(--primary);
    border-radius: 2px;
}
.menu-sort-item.dragging {
    opacity: 0.5;
}
.menu-sort-item .btn,
.menu-sort-item button {
    cursor: pointer;
}
.menu-sort-icon {
    font-size: 18px;
    flex-shrink: 0;
}
.menu-sort-title {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.menu-sort-title-main {
    font-weight: 500;
    color: var(--gray-900);
    font-size: 14px;
}
.menu-sort-title-sub {
    font-size: 12px;
    color: var(--gray-500);
}
.menu-sort-title-sub code {
    background: var(--gray-100);
    padding: 1px 6px;
    border-radius: 4px;
    font-size: 11px;
}
.menu-sort-tags {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.menu-sort-actions {
    display: flex;
    gap: 4px;
    flex-shrink: 0;
}
.menu-sort-actions .btn {
    padding: 3px 8px;
    font-size: 12px;
}
.menu-sort-empty {
    text-align: center;
    padding: 20px;
    color: var(--gray-400);
    font-size: 13px;
}
.menu-sort-notice {
    padding: 10px 14px;
    margin-bottom: 16px;
    background: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 8px;
    color: #1e40af;
    font-size: 13px;
}
.menu-sort-notice b {
    color: #1e3a8a;
}
