/* ===== 全局重置 ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
    --primary: #4f7cff;
    --primary-dark: #3a63d8;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --info: #06b6d4;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-w: 230px;
    --topbar-h: 56px;
    --radius: 8px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.05);
    --shadow: 0 2px 8px rgba(0,0,0,.08);
    --shadow-lg: 0 10px 30px rgba(0,0,0,.15);
}
html, body { height: 100%; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
    font-size: 14px;
    color: var(--gray-800);
    background: var(--gray-100);
    line-height: 1.5;
}
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-dark); }
button { font-family: inherit; cursor: pointer; }

/* ===== 登录页 ===== */
.login-body {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-wrap { width: 100%; max-width: 400px; }
.login-card {
    background: #fff;
    border-radius: 12px;
    padding: 40px 32px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-header { text-align: center; margin-bottom: 28px; }
.login-logo {
    width: 64px; height: 64px;
    margin: 0 auto 12px;
    background: linear-gradient(135deg, #667eea, #764ba2);
    color: #fff;
    border-radius: 16px;
    display: flex; align-items: center; justify-content: center;
    font-size: 32px;
}
.login-header h1 { font-size: 22px; color: var(--gray-800); margin-bottom: 4px; }
.login-sub { font-size: 12px; color: var(--gray-400); letter-spacing: 1px; }
.login-tip {
    margin-top: 20px;
    padding: 10px 14px;
    background: var(--gray-50);
    border-radius: 6px;
    font-size: 12px;
    color: var(--gray-500);
    text-align: center;
}

/* ===== 表单组件 ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    color: var(--gray-600);
    font-weight: 500;
}
.form-group .req { color: var(--danger); }
.form-group .hint { color: var(--gray-400); font-weight: normal; font-size: 12px; margin-left: 6px; }
.input, .form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    color: var(--gray-800);
    background: #fff;
    transition: border-color .15s, box-shadow .15s;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus, .input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(79,124,255,.15);
}
.form-group input:disabled { background: var(--gray-100); color: var(--gray-500); cursor: not-allowed; }
.form-row { display: flex; align-items: center; }
.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    font-size: 14px;
    color: var(--gray-700);
}
.checkbox input[type=checkbox] { width: 16px; height: 16px; cursor: pointer; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .full { grid-column: span 2; }

/* ===== 按钮 ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid transparent;
    border-radius: 6px;
    font-size: 14px;
    font-weight: 500;
    transition: all .15s;
    white-space: nowrap;
    background: #fff;
    color: var(--gray-700);
    border-color: var(--gray-300);
}
.btn:hover { background: var(--gray-50); }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #dc2626; }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-default { background: #fff; color: var(--gray-700); border-color: var(--gray-300); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; padding: 11px; font-size: 15px; }
.btn-link { background: none; border: none; color: var(--primary); padding: 4px 8px; }
.btn-link:hover { background: none; text-decoration: underline; }

/* ===== 提示框 ===== */
.alert {
    padding: 10px 14px;
    border-radius: 6px;
    margin-bottom: 14px;
    font-size: 13px;
    border: 1px solid transparent;
}
.alert-error, .alert-danger { background: #fee2e2; color: #991b1b; border-color: #fecaca; }
.alert-success { background: #d1fae5; color: #065f46; border-color: #a7f3d0; }
.alert-info    { background: #dbeafe; color: #1e40af; border-color: #bfdbfe; }
.alert-warning { background: #fef3c7; color: #92400e; border-color: #fde68a; }

/* ===== 主布局 ===== */
.layout { display: flex; min-height: 100vh; }
.sidebar {
    width: var(--sidebar-w);
    background: var(--gray-900);
    color: var(--gray-300);
    display: flex;
    flex-direction: column;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: transform .25s ease;
}
.brand {
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-logo { font-size: 22px; }
.brand-text { font-size: 15px; font-weight: 600; color: #fff; }
.nav { flex: 1; padding: 12px 0; overflow-y: auto; }
.nav-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 20px;
    color: var(--gray-400);
    font-size: 14px;
    transition: all .15s;
    border-left: 3px solid transparent;
}
.nav-item:hover { background: rgba(255,255,255,.05); color: #fff; }
.nav-item.active { background: rgba(79,124,255,.15); color: #fff; border-left-color: var(--primary); }
.nav-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-footer { border-top: 1px solid rgba(255,255,255,.08); }

.main { flex: 1; margin-left: var(--sidebar-w); display: flex; flex-direction: column; min-height: 100vh; }
.topbar {
    height: var(--topbar-h);
    background: #fff;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 50;
    gap: 12px;
}
.sidebar-toggle {
    background: none;
    border: none;
    font-size: 20px;
    color: var(--gray-600);
    padding: 4px 8px;
}
.sidebar-toggle:hover { color: var(--primary); }
.breadcrumb { flex: 1; font-size: 15px; font-weight: 600; color: var(--gray-800); }
.topbar-right { display: flex; align-items: center; gap: 12px; }
.user-menu {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 6px 10px;
    border-radius: 6px;
    position: relative;
}
.user-menu:hover { background: var(--gray-100); }
.user-avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    background: var(--primary);
    color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 14px;
}
.user-name { font-size: 13px; color: var(--gray-700); }
.user-role { font-size: 12px; color: var(--gray-400); }
.dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #fff;
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    box-shadow: var(--shadow);
    min-width: 140px;
    display: none;
    overflow: hidden;
}
.dropdown.show { display: block; }
.dropdown a {
    display: block;
    padding: 9px 14px;
    color: var(--gray-700);
    font-size: 13px;
    border-bottom: 1px solid var(--gray-100);
}
.dropdown a:last-child { border-bottom: none; }
.dropdown a:hover { background: var(--gray-50); color: var(--primary); }

.content { flex: 1; padding: 20px; }
.footer { padding: 12px 20px; text-align: center; color: var(--gray-400); font-size: 12px; border-top: 1px solid var(--gray-200); background: #fff; }

/* ===== 工具栏 ===== */
.toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    gap: 12px;
    flex-wrap: wrap;
}
.toolbar-left { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.toolbar-right { display: flex; align-items: center; gap: 8px; }
.total-info { font-size: 13px; color: var(--gray-500); }

/* ===== 面板/表格 ===== */
.panel {
    background: #fff;
    border-radius: var(--radius);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    margin-bottom: 16px;
}
.panel-header {
    padding: 14px 18px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.panel-header h3 { font-size: 15px; color: var(--gray-800); font-weight: 600; }
.panel-body { padding: 18px; }
.panel-body.no-pad { padding: 0; }

.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--gray-100);
    font-size: 13px;
}
.table th {
    background: var(--gray-50);
    color: var(--gray-600);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .3px;
}
.table tbody tr:hover { background: var(--gray-50); }
.table .empty { text-align: center; color: var(--gray-400); padding: 30px; }
.table-sm th, .table-sm td { padding: 7px 10px; font-size: 12px; }
.ellipsis { max-width: 260px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.table-info th { width: 120px; color: var(--gray-500); font-weight: 500; background: var(--gray-50); }
.table-info td { background: #fff; }

/* ===== 标签 ===== */
.tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 600;
    line-height: 1.6;
}
.tag-green  { background: #d1fae5; color: #065f46; }
.tag-red    { background: #fee2e2; color: #991b1b; }
.tag-orange { background: #ffedd5; color: #9a3412; }
.tag-blue   { background: #dbeafe; color: #1e40af; }
.tag-gray   { background: var(--gray-100); color: var(--gray-600); }
.tag-purple { background: #ede9fe; color: #5b21b6; }

/* ===== 统计卡片 ===== */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: #fff;
    border-radius: var(--radius);
    padding: 18px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--gray-200);
    transition: transform .15s, box-shadow .15s;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
}
.stat-blue   .stat-icon { background: #dbeafe; }
.stat-green  .stat-icon { background: #d1fae5; }
.stat-orange .stat-icon { background: #ffedd5; }
.stat-purple .stat-icon { background: #ede9fe; }
.stat-red    .stat-icon { background: #fee2e2; }
.stat-cyan   .stat-icon { background: #cffafe; }
.stat-num { font-size: 24px; font-weight: 700; color: var(--gray-800); }
.stat-label { font-size: 12px; color: var(--gray-500); }

/* ===== 两栏布局 ===== */
.grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
@media (max-width: 900px) {
    .grid-2 { grid-template-columns: 1fr; }
}

/* ===== 柱状图 ===== */
.bar-chart {
    display: flex;
    align-items: flex-end;
    justify-content: space-around;
    height: 160px;
    padding: 10px 0;
    gap: 8px;
}
.bar-item { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.bar-value { font-size: 11px; color: var(--gray-600); font-weight: 600; }
.bar {
    width: 70%;
    background: linear-gradient(180deg, var(--primary), #6691ff);
    border-radius: 4px 4px 0 0;
    min-height: 4px;
    transition: height .3s;
}
.bar-label { font-size: 11px; color: var(--gray-500); }

/* ===== 分页 ===== */
.pagination {
    display: flex;
    align-items: center;
    gap: 4px;
    margin-top: 16px;
    justify-content: flex-end;
    flex-wrap: wrap;
}
.page-btn {
    min-width: 32px;
    height: 32px;
    padding: 0 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--gray-300);
    border-radius: 4px;
    background: #fff;
    color: var(--gray-700);
    font-size: 13px;
}
.page-btn:hover:not(.disabled):not(.active) { border-color: var(--primary); color: var(--primary); }
.page-btn.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.page-btn.disabled { color: var(--gray-300); cursor: not-allowed; }
.page-info { font-size: 13px; color: var(--gray-500); margin-left: 8px; }

/* ===== 模态框 ===== */
.modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 20px;
}
.modal.show { display: flex; }
.modal-dialog {
    background: #fff;
    border-radius: 10px;
    width: 100%;
    max-width: 640px;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: var(--shadow-lg);
}
.modal-sm { max-width: 460px; }
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--gray-200);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 16px; font-weight: 600; color: var(--gray-800); }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    color: var(--gray-400);
    line-height: 1;
    padding: 0 4px;
}
.modal-close:hover { color: var(--gray-700); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-footer {
    padding: 14px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* ===== 角色管理布局 ===== */
.role-layout { display: grid; grid-template-columns: 280px 1fr; gap: 16px; }
@media (max-width: 900px) { .role-layout { grid-template-columns: 1fr; } }
.role-list {
    background: #fff;
    border-radius: var(--radius);
    border: 1px solid var(--gray-200);
    overflow: hidden;
}
.role-item {
    padding: 12px 16px;
    border-bottom: 1px solid var(--gray-100);
    cursor: pointer;
    transition: all .15s;
}
.role-item:hover { background: var(--gray-50); }
.role-item.active { background: rgba(79,124,255,.08); border-left: 3px solid var(--primary); padding-left: 13px; }
.role-item-name { font-size: 14px; font-weight: 600; color: var(--gray-800); display: flex; align-items: center; gap: 6px; }
.role-item-meta { font-size: 12px; color: var(--gray-400); margin-top: 3px; }
.role-desc { color: var(--gray-500); margin-bottom: 16px; font-size: 13px; }

/* ===== 权限树 ===== */
.perm-group {
    border: 1px solid var(--gray-200);
    border-radius: 6px;
    margin-bottom: 12px;
    overflow: hidden;
}
.perm-group-title {
    padding: 10px 14px;
    background: var(--gray-50);
    border-bottom: 1px solid var(--gray-200);
}
.perm-items {
    padding: 12px 14px;
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
    gap: 10px;
}
.perm-item { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.perm-code {
    color: var(--gray-400);
    font-size: 11px;
    font-family: "Consolas", "Monaco", monospace;
    background: var(--gray-100);
    padding: 1px 5px;
    border-radius: 3px;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.show { transform: translateX(0); }
    .main { margin-left: 0; }
    .form-grid { grid-template-columns: 1fr; }
    .form-grid .full { grid-column: span 1; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
}

/* ===== 滚动条美化 ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--gray-100); }
::-webkit-scrollbar-thumb { background: var(--gray-300); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--gray-400); }
