/* ============================================================
   大健康进销存财务系统 - 主样式表
   ============================================================ */

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

:root {
    --sidebar-width: 230px;
    --sidebar-bg: #1a2332;
    --sidebar-hover: #2a3548;
    --sidebar-active: #2d7d46;
    --primary: #2d7d46;
    --primary-light: #4caf50;
    --primary-dark: #1b5e20;
    --danger: #d32f2f;
    --danger-light: #ef5350;
    --warning: #f57c00;
    --warning-light: #ffb74d;
    --info: #0288d1;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text: #333;
    --text-light: #666;
    --text-lighter: #999;
    --border: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 8px;
    --topbar-height: 56px;
}

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

/* ============================================================
   布局
   ============================================================ */
#app { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: var(--sidebar-bg);
    color: #fff;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform 0.3s;
}

.sidebar-header {
    padding: 18px 20px;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    position: relative;
}
.sidebar-header h1 {
    font-size: 16px;
    font-weight: 600;
}
.sidebar-header .version {
    font-size: 11px;
    color: rgba(255,255,255,0.4);
}

.sidebar-nav { padding: 10px 0; }

.sidebar-nav { padding: 12px 0; }

.nav-divider {
    height: 1px;
    background: rgba(255,255,255,0.08);
    margin: 8px 16px;
}

.nav-section { margin-bottom: 4px; }
.nav-section-title {
    padding: 8px 16px 6px;
    font-size: 12px;
    color: rgba(255,255,255,0.35);
    font-weight: 600;
    letter-spacing: 0.3px;
    user-select: none;
}

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 3px 14px 3px 18px;
    margin: 1px 10px;
    color: rgba(255,255,255,0.75);
    text-decoration: none;
    font-size: 14px;
    border-radius: 6px;
    transition: all 0.2s ease;
    border-left: none;
}
.nav-item:hover {
    background: rgba(255,255,255,0.08);
    color: #fff;
}
.nav-item.active {
    background: var(--sidebar-active);
    color: #fff;
    font-weight: 500;
    box-shadow: 0 2px 8px rgba(45,125,70,0.3);
}
.nav-item .icon { font-size: 16px; width: 22px; text-align: center; display: inline-block; }
.nav-item .label { flex: 1; }

/* 旧版折叠菜单样式兼容 */
.nav-group { margin-bottom: 4px; }
.nav-group-title {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 9px 14px 9px 18px;
    margin: 1px 10px;
    font-size: 14px;
    color: rgba(255,255,255,0.75);
    font-weight: 500;
    border-radius: 6px;
    cursor: pointer;
    user-select: none;
    transition: all 0.2s;
}
.nav-group-title:hover { background: rgba(255,255,255,0.08); color: #fff; }
.nav-group-title .chevron { font-size: 11px; transition: transform 0.2s; }
.nav-group.collapsed .chevron { transform: rotate(-90deg); }
.nav-group-items {
    display: flex;
    flex-direction: column;
    padding-left: 8px;
}
.nav-group.collapsed .nav-group-items { display: none; }

.main-content {
    flex: 1;
    margin-left: var(--sidebar-width);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

.topbar {
    height: var(--topbar-height);
    background: var(--card-bg);
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    position: sticky;
    top: 0;
    z-index: 50;
}

.menu-toggle {
    display: none;
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--text);
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 16px;
}
.user-info { display: flex; align-items: center; gap: 8px; }
.user-name { font-weight: 600; }
.user-role {
    font-size: 12px;
    padding: 2px 8px;
    background: var(--primary);
    color: #fff;
    border-radius: 10px;
}
.btn-logout {
    color: var(--danger);
    text-decoration: none;
    font-size: 14px;
    padding: 4px 12px;
    border: 1px solid var(--danger);
    border-radius: 4px;
    transition: all 0.2s;
}
.btn-logout:hover { background: var(--danger); color: #fff; }

.page-content { padding: 20px; flex: 1; }

.page-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}
.page-header h2 { font-size: 20px; font-weight: 600; }

/* ============================================================
   卡片
   ============================================================ */
.card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    margin-bottom: 20px;
}
.card-title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 15px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--bg);
}

/* ============================================================
   统计卡片
   ============================================================ */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 20px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    position: relative;
    overflow: hidden;
}
.stat-card::before {
    content: '';
    position: absolute;
    top: 0; left: 0;
    width: 4px;
    height: 100%;
    background: var(--primary);
}
.stat-card.danger::before { background: var(--danger); }
.stat-card.warning::before { background: var(--warning); }
.stat-card.info::before { background: var(--info); }
.stat-card .stat-icon {
    position: absolute;
    right: 15px;
    top: 15px;
    font-size: 32px;
    opacity: 0.15;
}
.stat-card .stat-label {
    font-size: 13px;
    color: var(--text-light);
    margin-bottom: 8px;
}
.stat-card .stat-value {
    font-size: 24px;
    font-weight: 700;
    color: var(--text);
}
.stat-card .stat-sub {
    font-size: 12px;
    color: var(--text-lighter);
    margin-top: 5px;
}

/* ============================================================
   按钮
   ============================================================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: 5px;
    font-size: 14px;
    cursor: pointer;
    text-decoration: none;
    transition: all 0.2s;
    font-family: inherit;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #b71c1c; }
.btn-warning { background: var(--warning); color: #fff; }
.btn-success { background: var(--primary-light); color: #fff; }
.btn-info { background: var(--info); color: #fff; }
.btn-default { background: #f5f5f5; color: var(--text); border: 1px solid var(--border); }
.btn-default:hover { background: #e8e8e8; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 16px; }
.btn-block { display: flex; width: 100%; justify-content: center; }

/* ============================================================
   表格
   ============================================================ */
.table-wrap {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
}
thead th {
    background: #f5f7fa;
    padding: 12px 15px;
    text-align: left;
    font-weight: 600;
    font-size: 13px;
    color: var(--text-light);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
tbody td {
    padding: 10px 15px;
    border-bottom: 1px solid var(--border);
    font-size: 14px;
}
tbody tr:hover { background: #f9f9f9; }
tbody tr:last-child td { border-bottom: none; }

.text-right { text-align: right; }
.text-center { text-align: center; }
.text-danger { color: var(--danger); }
.text-success { color: var(--primary); }
.text-warning { color: var(--warning); }
.text-muted { color: var(--text-lighter); }
.font-bold { font-weight: 600; }

/* ============================================================
   状态标签
   ============================================================ */
.tag {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 10px;
    font-size: 12px;
    font-weight: 500;
}
.tag-success { background: #e8f5e9; color: #2e7d32; }
.tag-danger { background: #ffebee; color: #c62828; }
.tag-warning { background: #fff3e0; color: #e65100; }
.tag-info { background: #e3f2fd; color: #1565c0; }
.tag-default { background: #f5f5f5; color: #666; }

/* ============================================================
   表单
   ============================================================ */
.form-group {
    margin-bottom: 16px;
}
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 14px;
}
.form-group label .required { color: var(--danger); }
.form-control {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 5px;
    font-size: 14px;
    font-family: inherit;
    transition: border-color 0.2s;
    background: #fff;
}
.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(45,125,70,0.1);
}
.form-control:disabled { background: #f5f5f5; }
textarea.form-control { resize: vertical; min-height: 80px; }
select.form-control { cursor: pointer; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.form-inline {
    display: flex;
    gap: 10px;
    align-items: flex-end;
    flex-wrap: wrap;
    margin-bottom: 16px;
}

/* ============================================================
   模态框
   ============================================================ */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    justify-content: center;
    align-items: flex-start;
    padding: 40px 20px;
    overflow-y: auto;
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff;
    border-radius: var(--radius);
    width: 100%;
    max-width: 600px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    animation: slideUp 0.3s;
}
.modal.modal-lg { max-width: 900px; }
.modal.modal-sm { max-width: 400px; }
@keyframes slideUp {
    from { transform: translateY(-30px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
}
.modal-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}
.modal-header h3 { font-size: 18px; }
.modal-close {
    background: none;
    border: none;
    font-size: 24px;
    cursor: pointer;
    color: var(--text-lighter);
    line-height: 1;
}
.modal-body { padding: 20px; max-height: 70vh; overflow: visible; }

/* 修复模态框内select被裁剪的问题 */
.modal-body select.form-control,
.modal-body td select.form-control {
    min-width: 120px;
    position: relative;
    z-index: 1;
}
.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--border);
    display: flex;
    justify-content: flex-end;
    gap: 10px;
}

/* ============================================================
   提示消息
   ============================================================ */
.alert {
    padding: 12px 16px;
    border-radius: 5px;
    margin-bottom: 16px;
    font-size: 14px;
}
.alert-success { background: #e8f5e9; color: #2e7d32; border: 1px solid #c8e6c9; }
.alert-danger { background: #ffebee; color: #c62828; border: 1px solid #ffcdd2; }
.alert-warning { background: #fff3e0; color: #e65100; border: 1px solid #ffe0b2; }
.alert-info { background: #e3f2fd; color: #1565c0; border: 1px solid #bbdefb; }

/* ============================================================
   分页
   ============================================================ */
.pagination {
    display: flex;
    gap: 5px;
    justify-content: center;
    align-items: center;
    padding: 15px;
    flex-wrap: wrap;
}
.pagination a, .pagination span {
    padding: 6px 12px;
    border: 1px solid var(--border);
    border-radius: 4px;
    text-decoration: none;
    color: var(--text);
    font-size: 13px;
}
.pagination a:hover { background: var(--bg); }
.pagination .current {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.pagination .total { border: none; color: var(--text-light); }

/* ============================================================
   筛选栏
   ============================================================ */
.filter-bar {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px;
    margin-bottom: 16px;
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    align-items: flex-end;
}
.filter-bar .form-group { margin-bottom: 0; min-width: 150px; }

/* ============================================================
   行内操作按钮
   ============================================================ */
.action-btns { display: flex; gap: 5px; flex-wrap: nowrap; }
.action-btns .btn { padding: 3px 8px; font-size: 12px; }

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

/* ============================================================
   进度条/预警
   ============================================================ */
.progress-bar {
    width: 100%;
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}
.progress-bar .fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s;
}

/* ============================================================
   工具类
   ============================================================ */
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.gap-10 { gap: 10px; }
.gap-20 { gap: 20px; }
.mt-10 { margin-top: 10px; }
.mt-20 { margin-top: 20px; }
.mb-10 { margin-bottom: 10px; }
.mb-20 { margin-bottom: 20px; }
.hidden { display: none !important; }
.w-100 { width: 100%; }

/* ============================================================
   移动端适配
   ============================================================ */
@media (max-width: 768px) {
    .sidebar {
        transform: translateX(-100%);
        width: 260px;
    }
    .sidebar.show {
        transform: translateX(0);
    }
    .main-content {
        margin-left: 0;
    }
    .menu-toggle {
        display: block;
    }
    .page-content {
        padding: 12px;
    }
    .stats-grid {
        grid-template-columns: 1fr;
    }
    .form-row {
        grid-template-columns: 1fr;
    }
    .page-header {
        flex-direction: column;
        align-items: flex-start;
    }
    .filter-bar {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-bar .form-group { min-width: 100%; }
    .modal {
        max-width: 100%;
        margin: 10px;
    }
    .modal-body { max-height: none; }
    table { font-size: 12px; }
    thead th, tbody td { padding: 8px; }
    .topbar-right .user-role { display: none; }
    .nav-item { padding: 10px 14px 10px 18px; margin: 2px 8px; }
    .nav-section-title { padding: 10px 16px 8px; }
}

/* ============================================================
   特殊样式
   ============================================================ */
.tier-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 12px;
    font-weight: 500;
}
.tier-1 { background: #e3f2fd; color: #1565c0; }
.tier-2 { background: #f3e5f5; color: #7b1fa2; }
.tier-3 { background: #e8f5e9; color: #2e7d32; }
.tier-4 { background: #fff3e0; color: #e65100; }

.order-amount {
    font-weight: 600;
    color: var(--danger);
}

.profit-positive { color: var(--primary); font-weight: 600; }
.profit-negative { color: var(--danger); font-weight: 600; }

/* 打印样式 */
@media print {
    .sidebar, .topbar, .filter-bar, .action-btns, .pagination, .btn { display: none !important; }
    .main-content { margin-left: 0 !important; }
    .card, .table-wrap { box-shadow: none; border: 1px solid #ddd; }
}
