/* ============================================================
   全局样式 - 公司内部管理系统
   蓝白主色调，办公风格
   ============================================================ */

/* CSS 变量定义 */
:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --secondary: #5f6368;
    --success: #0f9d58;
    --warning: #f9ab00;
    --danger: #d93025;
    --info: #4285f4;

    --bg-body: #f5f6fa;
    --bg-white: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-header: #ffffff;
    --bg-card: #ffffff;

    --text-primary: #202124;
    --text-secondary: #5f6368;
    --text-muted: #9aa0a6;
    --text-light: #ffffff;
    --text-sidebar: #cbd5e1;
    --text-sidebar-hover: #ffffff;

    --border-color: #e0e0e0;
    --border-light: #f0f0f0;

    --shadow-sm: 0 1px 2px rgba(0,0,0,0.06);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.08);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.1);

    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;

    --font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    --font-size-xs: 12px;
    --font-size-sm: 13px;
    --font-size-base: 14px;
    --font-size-lg: 16px;
    --font-size-xl: 20px;
    --font-size-2xl: 24px;

    --sidebar-width: 220px;
    --header-height: 56px;

    --transition: all 0.3s ease;
}

/* 暗色模式 */
[data-theme="dark"] {
    --bg-body: #0f172a;
    --bg-white: #1e293b;
    --bg-sidebar: #0f172a;
    --bg-header: #1e293b;
    --bg-card: #1e293b;
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border-color: #334155;
    --border-light: #1e293b;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.3);
    --shadow-md: 0 2px 8px rgba(0,0,0,0.4);
    --shadow-lg: 0 4px 16px rgba(0,0,0,0.5);
}

/* 重置样式 */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: var(--font-size-base);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-family);
    color: var(--text-primary);
    background: var(--bg-body);
    line-height: 1.6;
    min-height: 100vh;
}

a {
    color: var(--primary);
    text-decoration: none;
}
a:hover {
    color: var(--primary-dark);
}

img {
    max-width: 100%;
    height: auto;
}

/* ============================================================
   按钮
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: var(--font-size-base);
    font-weight: 500;
    border: 1px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: var(--transition);
    line-height: 1.5;
    white-space: nowrap;
    user-select: none;
}
.btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}
.btn-primary {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.btn-primary:hover:not(:disabled) {
    background: var(--primary-dark);
    border-color: var(--primary-dark);
}
.btn-danger {
    background: var(--danger);
    color: #fff;
    border-color: var(--danger);
}
.btn-danger:hover:not(:disabled) {
    background: #c62828;
}
.btn-success {
    background: var(--success);
    color: #fff;
    border-color: var(--success);
}
.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}
.btn-outline:hover:not(:disabled) {
    background: var(--bg-body);
    border-color: var(--text-secondary);
}
.btn-sm {
    padding: 4px 10px;
    font-size: var(--font-size-sm);
}
.btn-lg {
    padding: 12px 24px;
    font-size: var(--font-size-lg);
}
.btn-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-secondary);
    line-height: 1;
    padding: 4px;
}
.btn-close:hover {
    color: var(--text-primary);
}
.btn-icon {
    padding: 6px;
    border-radius: 50%;
    background: transparent;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
}
.btn-icon:hover {
    background: var(--bg-body);
    color: var(--text-primary);
}

/* ============================================================
   表单
   ============================================================ */
.form-group {
    margin-bottom: 16px;
}
.form-label {
    display: block;
    margin-bottom: 6px;
    font-size: var(--font-size-sm);
    font-weight: 500;
    color: var(--text-primary);
}
.form-label .required {
    color: var(--danger);
    margin-left: 2px;
}
.form-input,
.form-select,
.form-textarea {
    width: 100%;
    padding: 8px 12px;
    font-size: var(--font-size-base);
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    transition: var(--transition);
    outline: none;
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(26, 115, 232, 0.15);
}
.form-input.error,
.form-select.error {
    border-color: var(--danger);
}
.form-textarea {
    resize: vertical;
    min-height: 80px;
}
.form-hint {
    font-size: var(--font-size-xs);
    color: var(--text-muted);
    margin-top: 4px;
}
.form-error {
    font-size: var(--font-size-xs);
    color: var(--danger);
    margin-top: 4px;
}
.form-row {
    display: flex;
    gap: 16px;
}
.form-row > .form-group {
    flex: 1;
}

/* 复选框 */
.checkbox-label {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    font-size: var(--font-size-base);
}
.checkbox-label input[type="checkbox"] {
    width: 16px;
    height: 16px;
    cursor: pointer;
}

/* 开关 */
.toggle-switch {
    position: relative;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}
.toggle-switch input {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
}
.toggle-slider {
    position: relative;
    width: 44px;
    height: 24px;
    background: var(--border-color);
    border-radius: 12px;
    transition: var(--transition);
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 20px;
    height: 20px;
    left: 2px;
    top: 2px;
    background: #fff;
    border-radius: 50%;
    transition: var(--transition);
}
.toggle-switch input:checked + .toggle-slider {
    background: var(--primary);
}
.toggle-switch input:checked + .toggle-slider::before {
    transform: translateX(20px);
}

/* ============================================================
   卡片
   ============================================================ */
.card {
    background: var(--bg-card);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    margin-bottom: 16px;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.card-header h2,
.card-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
}
.card-body {
    padding: 20px;
}
.card-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* ============================================================
   表格
   ============================================================ */
.table-container {
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
table th,
table td {
    padding: 10px 12px;
    text-align: left;
    border-bottom: 1px solid var(--border-light);
    font-size: var(--font-size-sm);
}
table th {
    background: var(--bg-body);
    font-weight: 600;
    color: var(--text-secondary);
    white-space: nowrap;
}
table tr:hover {
    background: var(--primary-light);
}
table tr.selected {
    background: rgba(26, 115, 232, 0.08);
}

/* ============================================================
   标签/徽章
   ============================================================ */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--font-size-xs);
    font-weight: 500;
    border-radius: 10px;
}
.badge-primary {
    background: var(--primary-light);
    color: var(--primary);
}
.badge-success {
    background: #e6f4ea;
    color: var(--success);
}
.badge-warning {
    background: #fef7e0;
    color: var(--warning);
}
.badge-danger {
    background: #fce8e6;
    color: var(--danger);
}
.badge-info {
    background: #e8f0fe;
    color: var(--info);
}

.role-badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 8px;
    font-size: var(--font-size-xs);
    font-weight: 500;
    border-radius: 10px;
    background: var(--primary-light);
    color: var(--primary);
}
.role-badge.super_admin {
    background: #fff3e0;
    color: #e65100;
}
.role-badge.admin {
    background: #e8f5e9;
    color: #2e7d32;
}
.role-badge.user {
    background: #e3f2fd;
    color: #1565c0;
}

/* ============================================================
   分页
   ============================================================ */
.pagination {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 4px;
    padding: 16px 0;
}
.pagination button {
    padding: 6px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-sm);
    background: var(--bg-white);
    color: var(--text-primary);
    cursor: pointer;
    font-size: var(--font-size-sm);
    transition: var(--transition);
}
.pagination button:hover:not(:disabled) {
    background: var(--primary-light);
    border-color: var(--primary);
}
.pagination button.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.pagination button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}
.pagination .page-info {
    padding: 0 12px;
    font-size: var(--font-size-sm);
    color: var(--text-secondary);
}

/* ============================================================
   弹窗/模态框
   ============================================================ */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    animation: fadeIn 0.2s ease;
}
.modal {
    background: var(--bg-card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 90%;
    max-width: 520px;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}
.modal-lg {
    max-width: 720px;
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 {
    font-size: var(--font-size-lg);
    font-weight: 600;
}
.modal-body {
    padding: 20px;
}
.modal-footer {
    padding: 12px 20px;
    border-top: 1px solid var(--border-light);
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
}

/* ============================================================
   提示消息
   ============================================================ */
.toast {
    position: fixed;
    top: 20px;
    right: 20px;
    padding: 12px 20px;
    border-radius: var(--radius-md);
    color: #fff;
    font-size: var(--font-size-base);
    z-index: 2000;
    animation: slideInRight 0.3s ease;
    box-shadow: var(--shadow-lg);
    max-width: 400px;
}
.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-warning { background: var(--warning); color: #333; }
.toast-info { background: var(--info); }

/* ============================================================
   工具类
   ============================================================ */
.text-center { text-align: center; }
.text-right { text-align: right; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-primary { color: var(--primary); }

.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.flex-gap { gap: 8px; }
.flex-1 { flex: 1; }

.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mt-24 { margin-top: 24px; }
.mb-8 { margin-bottom: 8px; }
.mb-16 { margin-bottom: 16px; }
.ml-8 { margin-left: 8px; }
.mr-8 { margin-right: 8px; }

.p-16 { padding: 16px; }
.p-20 { padding: 20px; }

.w-full { width: 100%; }

/* 加载动画 */
.spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto;
}
.page-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 20px;
    color: var(--text-muted);
}
.page-loading .spinner {
    margin-bottom: 16px;
}

/* 空状态 */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon {
    font-size: 48px;
    margin-bottom: 16px;
}

/* 搜索栏 */
.search-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
    flex-wrap: wrap;
}
.search-bar .form-input {
    max-width: 280px;
}
.search-bar .form-select {
    max-width: 160px;
}

/* 过滤栏 */
.filter-bar {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
    padding: 12px 0;
}

/* 动画 */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes slideUp {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
@keyframes slideInRight {
    from { transform: translateX(100%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ============================================================
   响应式
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -280px;
        top: var(--header-height);
        bottom: 0;
        z-index: 100;
        transition: left 0.3s ease;
    }
    .sidebar.open {
        left: 0;
    }
    .main-container.sidebar-open .content-area {
        margin-left: 0;
    }
    .form-row {
        flex-direction: column;
        gap: 0;
    }
    .search-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .search-bar .form-input,
    .search-bar .form-select {
        max-width: 100%;
    }
    .table-container {
        font-size: var(--font-size-xs);
    }
}
