/* 编制管理系统 - 温暖色调UI */

:root {
    /* 主色调 - 温暖橙红 */
    --primary-50: #fff7ed;
    --primary-100: #ffedd5;
    --primary-200: #fed7aa;
    --primary-300: #fdba74;
    --primary-400: #fb923c;
    --primary-500: #f97316;
    --primary-600: #ea580c;
    --primary-700: #c2410c;
    --primary-800: #9a3412;
    --primary-900: #7c2d12;

    /* 中性色 */
    --gray-50: #fafaf9;
    --gray-100: #f5f5f4;
    --gray-200: #e7e5e4;
    --gray-300: #d6d3d1;
    --gray-400: #a8a29e;
    --gray-500: #78716c;
    --gray-600: #57534e;
    --gray-700: #44403c;
    --gray-800: #292524;
    --gray-900: #1c1917;

    /* 功能色 */
    --success: #22c55e;
    --success-light: #dcfce7;
    --warning: #eab308;
    --warning-light: #fef9c3;
    --error: #ef4444;
    --error-light: #fee2e2;
    --info: #06b6d4;
    --info-light: #cffafe;

    /* 语义化颜色 */
    --bg-body: #faf5f0;
    --bg-card: #ffffff;
    --bg-sidebar: #7c2d12;
    --text-primary: #1c1917;
    --text-secondary: #57534e;
    --text-muted: #a8a29e;
    --border-color: #e7e5e4;

    /* 阴影 */
    --shadow-sm: 0 1px 2px 0 rgb(0 0 0 / 0.05);
    --shadow: 0 1px 3px 0 rgb(0 0 0 / 0.1), 0 1px 2px -1px rgb(0 0 0 / 0.1);
    --shadow-md: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);

    /* 尺寸 */
    --sidebar-width: 240px;
    --header-height: 64px;
    --border-radius: 8px;

    /* 过渡 */
    --transition: all 0.2s ease;
}

/* 夜间模式 */
[data-theme="dark"] {
    --bg-body: #1c1917;
    --bg-card: #292524;
    --bg-sidebar: #1c1917;
    --text-primary: #fafaf9;
    --text-secondary: #a8a29e;
    --text-muted: #78716c;
    --border-color: #44403c;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Microsoft YaHei', sans-serif;
    font-size: 14px;
    line-height: 1.6;
    color: var(--text-primary);
    background-color: var(--bg-body);
    transition: var(--transition);
}

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

/* 登录页面 */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #f97316 0%, #dc2626 100%);
    background-size: cover;
    background-position: center;
    background-attachment: fixed;
    padding: 20px;
}

.login-container { width: 100%; max-width: 420px; padding: 0; }

.login-box {
    background: rgba(255, 255, 255, 0.95);
    backdrop-filter: blur(12px);
    border-radius: 12px;
    padding: 30px;
    box-shadow: var(--shadow-md);
    width: 100%;
}

@media (min-width: 480px) {
    .login-box { padding: 40px; }
}

.login-header { text-align: center; margin-bottom: 30px; }
.login-header h1 { font-size: 24px; font-weight: 700; color: var(--text-primary); margin-bottom: 8px; }
.login-header p { color: var(--text-secondary); font-size: 14px; }

.login-form .form-group { margin-bottom: 20px; }
.login-form label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-primary); }
.login-form input, .login-form select {
    width: 100%;
    height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 14px;
    transition: var(--transition);
    background: var(--bg-card);
}
.login-form input:focus, .login-form select:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}

.login-tabs { display: flex; margin-bottom: 24px; border-bottom: 1px solid var(--border-color); }
.login-tab {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    font-size: 14px;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    border-bottom: 2px solid transparent;
}
.login-tab:hover { color: var(--primary-500); }
.login-tab.active { color: var(--primary-500); border-bottom-color: var(--primary-500); }

/* 按钮 */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    height: 40px;
    padding: 10px 20px;
    border: none;
    border-radius: var(--border-radius);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background-color: var(--primary-500); color: white; }
.btn-primary:hover { background-color: var(--primary-600); }
.btn-secondary { background-color: var(--gray-100); color: var(--text-primary); }
.btn-secondary:hover { background-color: var(--gray-200); }
.btn-success { background-color: var(--success); color: white; }
.btn-success:hover { background-color: #16a34a; }
.btn-danger { background-color: var(--error); color: white; }
.btn-danger:hover { background-color: #dc2626; }
.btn-warning { background-color: var(--warning); color: white; }
.btn-block { width: 100%; }
.btn-sm { height: 32px; padding: 6px 12px; font-size: 13px; }
.btn-lg { height: 48px; padding: 12px 24px; font-size: 16px; }

/* 应用容器 */
.app-container { display: flex; min-height: 100vh; }

/* 移动端侧边栏切换按钮 */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 44px;
    height: 44px;
    background: var(--primary-500);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    box-shadow: var(--shadow);
}

@media (max-width: 768px) {
    .mobile-menu-btn { display: flex; align-items: center; justify-content: center; }
}

/* 移动端遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 140;
}

.sidebar-overlay.active { display: block; }

/* 侧边栏 */
.sidebar {
    width: var(--sidebar-width);
    background-color: var(--bg-sidebar);
    color: #fafaf9;
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    display: flex;
    flex-direction: column;
    z-index: 100;
}
.sidebar-header { padding: 20px; border-bottom: 1px solid rgba(255,255,255,0.1); }
.sidebar-header h2 { font-size: 18px; font-weight: 600; }
.sidebar-nav { flex: 1; padding: 16px 0; }
.nav-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: #d6d3d1;
    transition: var(--transition);
}
.nav-item:hover { background-color: rgba(255,255,255,0.1); color: #fafaf9; }
.nav-item.active {
    background-color: rgba(249, 115, 22, 0.3);
    color: #fb923c;
    border-left: 4px solid var(--primary-500);
}
.nav-icon { margin-right: 12px; font-size: 18px; }
.sidebar-footer { padding: 20px; border-top: 1px solid rgba(255,255,255,0.1); }

/* 主内容区 */
.main-content { flex: 1; margin-left: var(--sidebar-width); min-height: 100vh; }

/* 顶部栏 */
.topbar {
    height: var(--header-height);
    background-color: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 24px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar h1 { font-size: 18px; font-weight: 600; }
.user-info { display: flex; align-items: center; gap: 16px; }

/* 内容区 */
.content-area { padding: 24px; }

/* 卡片 */
.card {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    margin-bottom: 20px;
    box-shadow: var(--shadow-sm);
}
.card-header { padding: 16px 20px; border-bottom: 1px solid var(--border-color); }
.card-header h2 { font-size: 16px; font-weight: 600; }
.card-body { padding: 20px; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 12px 16px; text-align: left; border-bottom: 1px solid var(--border-color); }
.table th { background-color: var(--gray-50); font-weight: 600; font-size: 12px; text-transform: uppercase; color: var(--text-secondary); }
.table tr:hover { background-color: var(--gray-50); }
[data-theme="dark"] .table th, [data-theme="dark"] .table tr:hover { background-color: rgba(255,255,255,0.05); }

/* 表单 */
.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; color: var(--text-primary); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 14px;
    background-color: var(--bg-card);
    color: var(--text-primary);
    transition: var(--transition);
}
.form-group textarea { height: auto; min-height: 100px; resize: vertical; }
.form-group input:focus, .form-group select:focus, .form-group textarea:focus {
    outline: none;
    border-color: var(--primary-500);
    box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.2);
}
.form-actions { display: flex; gap: 12px; justify-content: center; margin-top: 24px; }
.help-text { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

/* 徽章 */
.badge { display: inline-block; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 500; }
.badge-success { background-color: var(--success-light); color: var(--success); }
.badge-warning { background-color: var(--warning-light); color: var(--warning); }

/* 模态框 */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0,0,0,0.5);
    align-items: center;
    justify-content: center;
    z-index: 1000;
}
.modal-content { background-color: var(--bg-card); border-radius: 12px; width: 90%; max-width: 500px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border-color); }
.modal-header h2 { font-size: 18px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 24px; cursor: pointer; color: var(--text-muted); }
.modal-body { padding: 20px; }

/* 筛选栏 */
.filter-bar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.filter-bar select, .filter-bar input {
    height: 40px;
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    background-color: var(--bg-card);
    color: var(--text-primary);
    min-width: 150px;
}

/* 文件列表 */
.file-list { margin-top: 10px; }
.file-item { display: flex; align-items: center; justify-content: space-between; padding: 8px 12px; background: var(--gray-100); border-radius: 4px; margin-bottom: 8px; }
.file-item a { color: var(--primary-500); }

/* 状态提示 */
.loading, .empty { text-align: center; color: var(--text-muted); padding: 40px; }

/* 响应式 */
@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; }
    
    .topbar { padding: 0 16px; }
    .topbar h1 { font-size: 16px; }
    
    .content-area { padding: 16px; }
    
    .filter-bar { 
        flex-direction: column; 
        align-items: stretch; 
    }
    .filter-bar select, 
    .filter-bar input, 
    .filter-bar button {
        width: 100%;
    }
    
    .card-body { padding: 16px; }
    
    .form-actions { 
        flex-direction: column; 
    }
    .form-actions .btn {
        width: 100%;
    }
    
    /* 表格横向滚动 */
    .card-body { 
        overflow-x: auto; 
        -webkit-overflow-scrolling: touch;
    }
    
    /* 模态框 */
    .modal-content { 
        width: 95%; 
        max-height: 90vh;
        overflow-y: auto;
    }
    
    /* 统计卡片 */
    .stats-grid { grid-template-columns: 1fr; }
    
    /* 单位表格 */
    .full-table { font-size: 11px; }
    .full-table th, .full-table td { padding: 6px 4px; }
    .full-table td.remark { max-width: 100px; }
}

@media (max-width: 480px) {
    .login-box { padding: 24px 16px; }
    .login-header h1 { font-size: 20px; }
    .login-tabs { font-size: 13px; }
    
    .btn { height: 44px; }
    .btn-sm { height: 36px; }
    
    .unit-header { 
        flex-direction: column; 
        gap: 12px;
        align-items: flex-start;
    }
    .unit-header h3 { font-size: 16px; }
    
    .action-btns { flex-direction: column; }
    .action-btns .btn { width: 100%; }
}

/* 表格响应式容器 */
.table-responsive {
    width: 100%;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* 移动端侧边栏切换按钮 */
.mobile-menu-btn {
    display: none;
    position: fixed;
    top: 12px;
    left: 12px;
    z-index: 200;
    width: 44px;
    height: 44px;
    background: var(--primary-500);
    color: white;
    border: none;
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
}

@media (max-width: 768px) {
    .mobile-menu-btn { display: block; }
    .sidebar { z-index: 150; }
}

/* 移动端遮罩 */
.sidebar-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 140;
}

.sidebar-overlay.active { display: block; }

/* ===== 多标签页 ===== */
.tab-bar {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    padding: 6px 16px 0;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border-color);
    overflow-x: auto;
    position: sticky;
    top: var(--header-height);
    z-index: 45;
    min-height: 40px;
}
.tab-bar::-webkit-scrollbar { height: 4px; }
.tab-bar::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 2px; }
.tab-item {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px 6px 12px;
    background: var(--gray-100);
    border: 1px solid var(--border-color);
    border-bottom: none;
    border-radius: 6px 6px 0 0;
    cursor: pointer;
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    transition: background 0.15s, color 0.15s;
    user-select: none;
    max-width: 220px;
}
.tab-item:hover { background: var(--gray-200); color: var(--text-primary); }
.tab-item.active {
    background: var(--bg-card);
    color: var(--primary-500);
    font-weight: 600;
    border-bottom: 1px solid var(--bg-card);
    margin-bottom: -1px;
}
.tab-title { overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.tab-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    color: var(--text-secondary);
    font-size: 16px;
    line-height: 1;
    flex-shrink: 0;
}
.tab-close:hover { background: var(--error, #ef4444); color: #fff; }
.tab-panels { position: relative; }
.tab-panel { display: none; }
.tab-panel.active { display: block; }
.tab-panel.iframe-panel { padding: 0; background: var(--bg-primary); }
.tab-panel iframe {
    width: 100%;
    height: calc(100vh - var(--header-height) - 40px);
    border: 0;
    display: block;
    background: var(--bg-primary);
}

/* 嵌入模式（iframe 内）隐藏外层导航 */
body.embedded .sidebar,
body.embedded .topbar,
body.embedded .mobile-menu-btn,
body.embedded .sidebar-overlay { display: none !important; }
body.embedded .main-content { margin-left: 0 !important; }
body.embedded .app-container { display: block; }

@media (max-width: 768px) {
    .tab-bar { padding: 6px 10px 0; }
    .tab-item { max-width: 140px; font-size: 12px; }
    .tab-title { max-width: 90px; }
}