/* ═══════════════════════════════════════
   工业ERP系统 - 样式表（移动端适配版）
   ═══════════════════════════════════════ */

:root {
    --primary: #1a73e8;
    --primary-dark: #1557b0;
    --primary-light: #e8f0fe;
    --success: #34a853;
    --danger: #ea4335;
    --warning: #fbbc04;
    --info: #4285f4;
    --bg: #f0f2f5;
    --sidebar-bg: #1e293b;
    --sidebar-active: #334155;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-secondary: #6b7280;
    --border: #e5e7eb;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.15);
    --radius: 8px;
    --sidebar-width: 240px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

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

/* ── 登录页 ── */
.login-container {
    display: flex; justify-content: center; align-items: center;
    min-height: 100vh; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    padding: 16px;
}
.login-box {
    background: white; padding: 48px; border-radius: 16px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.2); width: 400px; max-width: 100%;
}
.login-box h1 { text-align: center; margin-bottom: 8px; font-size: 28px; color: var(--text); }
.login-box p { text-align: center; color: var(--text-secondary); margin-bottom: 32px; }
.login-box .form-group { margin-bottom: 20px; }
.login-box label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 14px; }
.login-box input {
    width: 100%; padding: 12px 16px; border: 1px solid var(--border);
    border-radius: var(--radius); font-size: 16px; transition: border 0.2s;
}
.login-box input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(26,115,232,0.1); }
.login-box button {
    width: 100%; padding: 14px; background: var(--primary); color: white;
    border: none; border-radius: var(--radius); font-size: 16px; font-weight: 600;
    cursor: pointer; transition: background 0.2s;
}
.login-box button:hover { background: var(--primary-dark); }

/* ── 整体布局 ── */
.layout { display: flex; min-height: 100vh; }

/* ── 侧边栏 ── */
.sidebar {
    width: var(--sidebar-width); background: var(--sidebar-bg); color: #e2e8f0;
    display: flex; flex-direction: column; position: fixed;
    top: 0; left: 0; bottom: 0; z-index: 200;
    transition: transform 0.3s ease;
}
.sidebar-header {
    padding: 24px 20px; border-bottom: 1px solid rgba(255,255,255,0.08);
}
.sidebar-header h2 { font-size: 20px; color: white; display: flex; align-items: center; gap: 8px; }
.sidebar-header span { font-size: 12px; color: #94a3b8; display: block; margin-top: 4px; }
.sidebar-nav { flex: 1; padding: 16px 12px; overflow-y: auto; }
.sidebar-nav a {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; color: #94a3b8; border-radius: var(--radius);
    font-size: 14px; margin-bottom: 4px; transition: all 0.2s;
}
.sidebar-nav a:hover { background: var(--sidebar-active); color: white; }
.sidebar-nav a.active { background: var(--primary); color: white; }
.sidebar-nav a .icon { font-size: 18px; width: 24px; text-align: center; }
.sidebar-footer {
    padding: 16px 20px; border-top: 1px solid rgba(255,255,255,0.08);
    font-size: 13px;
}
.sidebar-footer a { color: #94a3b8; display: flex; align-items: center; gap: 8px; }
.sidebar-footer a:hover { color: white; }

/* 侧边栏遮罩层 */
.sidebar-overlay {
    display: none; position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.5); z-index: 150;
    opacity: 0; transition: opacity 0.3s ease;
}
.sidebar-overlay.active { display: block; opacity: 1; }

/* 汉堡菜单按钮（默认隐藏，移动端显示） */
.menu-toggle {
    display: none; background: none; border: none; cursor: pointer;
    padding: 8px; font-size: 24px; color: var(--text);
    line-height: 1; border-radius: 6px; transition: background 0.2s;
}
.menu-toggle:hover { background: #f3f4f6; }

/* 侧边栏关闭按钮（默认隐藏，移动端显示） */
.sidebar-close {
    display: none; position: absolute; top: 16px; right: 16px;
    background: none; border: none; cursor: pointer;
    color: #94a3b8; font-size: 24px; padding: 4px;
    line-height: 1; z-index: 10;
}
.sidebar-close:hover { color: white; }

/* ── 主内容区 ── */
.main { flex: 1; margin-left: var(--sidebar-width); }
.topbar {
    background: white; padding: 16px 32px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    position: sticky; top: 0; z-index: 50;
}
.topbar h1 { font-size: 20px; font-weight: 600; }
.topbar-left { display: flex; align-items: center; gap: 12px; }
.topbar .user-info { font-size: 14px; color: var(--text-secondary); }
.content { padding: 24px 32px; }

/* ── 统计卡片 ── */
.stats-grid {
    display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 20px; margin-bottom: 28px;
}
.stat-card {
    background: white; border-radius: var(--radius); padding: 24px;
    box-shadow: var(--shadow); border-left: 4px solid var(--primary);
}
.stat-card.success { border-left-color: var(--success); }
.stat-card.danger { border-left-color: var(--danger); }
.stat-card.warning { border-left-color: var(--warning); }
.stat-card .stat-label { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.stat-card .stat-value { font-size: 28px; font-weight: 700; }
.stat-card .stat-value.income { color: var(--success); }
.stat-card .stat-value.expense { color: var(--danger); }

/* ── 卡片 ── */
.card {
    background: white; border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 24px;
}
.card-header {
    padding: 20px 24px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
    gap: 12px; flex-wrap: wrap;
}
.card-header h3 { font-size: 16px; font-weight: 600; }
.card-body { padding: 24px; }

/* ── 表格 ── */
.table-wrapper { overflow-x: auto; -webkit-overflow-scrolling: touch; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
thead { background: #f9fafb; }
th { padding: 12px 16px; text-align: left; font-weight: 600; color: var(--text-secondary); font-size: 13px; white-space: nowrap; border-bottom: 2px solid var(--border); }
td { padding: 12px 16px; border-bottom: 1px solid var(--border); }
tr:hover { background: #f9fafb; }

/* ── 移动端卡片式列表（替代表格） ── */
.mobile-cards { display: none; }
.mobile-card-item {
    background: white; border-radius: var(--radius); padding: 16px;
    margin-bottom: 12px; box-shadow: var(--shadow);
    border-left: 3px solid var(--primary);
}
.mobile-card-item .card-row {
    display: flex; justify-content: space-between; align-items: center;
    padding: 6px 0; font-size: 14px;
}
.mobile-card-item .card-row:not(:last-child) {
    border-bottom: 1px solid #f3f4f6;
}
.mobile-card-item .card-label {
    color: var(--text-secondary); font-size: 13px; flex-shrink: 0; margin-right: 12px;
}
.mobile-card-item .card-value {
    font-weight: 500; text-align: right; word-break: break-all;
}
.mobile-card-item .card-title {
    font-size: 16px; font-weight: 600; margin-bottom: 8px;
    padding-bottom: 8px; border-bottom: 1px solid var(--border);
    display: flex; justify-content: space-between; align-items: center;
}
.mobile-card-item .card-actions {
    display: flex; gap: 8px; margin-top: 12px; padding-top: 12px;
    border-top: 1px solid #f3f4f6;
}

/* ── 表单 ── */
.form-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.form-group { flex: 1; min-width: 180px; }
.form-group label { display: block; margin-bottom: 6px; font-weight: 500; font-size: 13px; color: var(--text-secondary); }
.form-group input, .form-group select, .form-group textarea {
    width: 100%; padding: 10px 12px; border: 1px solid var(--border);
    border-radius: 6px; font-size: 16px; transition: border 0.2s;
    -webkit-appearance: none;
}
.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(26,115,232,0.1);
}

/* ── 按钮 ── */
.btn {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 10px 20px; border-radius: 6px; font-size: 14px; font-weight: 500;
    border: none; cursor: pointer; transition: all 0.2s;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #d33426; }
.btn-sm { padding: 6px 12px; font-size: 13px; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { background: #f3f4f6; }

/* ── 标签 ── */
.badge {
    display: inline-block; padding: 4px 10px; border-radius: 20px;
    font-size: 12px; font-weight: 500;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-danger { background: #fee2e2; color: #991b1b; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-info { background: #dbeafe; color: #1e40af; }
.badge-default { background: #f3f4f6; color: #374151; }

/* ── 提示消息 ── */
.flash-messages { padding: 0 32px; margin-top: 16px; }
.flash {
    padding: 12px 20px; border-radius: 6px; margin-bottom: 12px;
    font-size: 14px; animation: fadeIn 0.3s;
}
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #6ee7b7; }
.flash-error { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }

@keyframes fadeIn { from { opacity: 0; transform: translateY(-8px); } to { opacity: 1; transform: translateY(0); } }

/* ── 模态框 ── */
.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: center;
}
.modal-overlay.active { display: flex; }
.modal {
    background: white; border-radius: 12px; padding: 32px;
    width: 600px; max-width: 90%; max-height: 85vh; overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3); animation: slideUp 0.3s;
}
.modal h3 { margin-bottom: 24px; font-size: 18px; }

@keyframes slideUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }

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

/* ═══════════════════════════════════════
   移动端适配 (≤768px)
   ═══════════════════════════════════════ */
@media (max-width: 768px) {
    /* -- 订单统计面板 -- */
    div[style*="grid-template-columns:1fr 1fr"] {
        grid-template-columns: 1fr !important;
    }
    /* -- 侧边栏：抽屉式 -- */
    .sidebar {
        transform: translateX(-100%);
        width: 280px;
        box-shadow: 4px 0 20px rgba(0,0,0,0.3);
    }
    .sidebar.open { transform: translateX(0); }
    .sidebar-close { display: block; }
    .menu-toggle { display: block; }

    /* -- 主内容：全宽 -- */
    .main { margin-left: 0; }

    /* -- 顶部栏 -- */
    .topbar { padding: 12px 16px; }
    .topbar h1 { font-size: 17px; }
    .topbar .user-info { font-size: 12px; }

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

    /* -- 统计卡片：两列 -- */
    .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 20px; }
    .stat-card { padding: 16px; }
    .stat-card .stat-value { font-size: 22px; }
    .stat-card .stat-label { font-size: 12px; }

    /* -- 卡片 -- */
    .card-header { padding: 16px; }
    .card-header h3 { font-size: 15px; }
    .card-body { padding: 16px; }

    /* -- 表格隐藏，卡片列表显示 -- */
    .table-wrapper { display: none; }
    .mobile-cards { display: block; }

    /* -- 表单 -- */
    .form-row { flex-direction: column; gap: 12px; }
    .form-group { min-width: 100%; }
    .form-group input, .form-group select, .form-group textarea {
        padding: 12px; font-size: 16px;
    }

    /* -- 模态框：接近全屏 -- */
    .modal {
        width: 100%; max-width: 100%; max-height: 100vh;
        border-radius: 16px 16px 0 0; padding: 24px 20px;
        position: fixed; bottom: 0; left: 0; right: 0;
        animation: slideUpMobile 0.3s;
    }
    .modal-overlay.active { align-items: flex-end; }
    .modal h3 { font-size: 17px; margin-bottom: 20px; }

    @keyframes slideUpMobile {
        from { opacity: 0; transform: translateY(100%); }
        to { opacity: 1; transform: translateY(0); }
    }

    /* -- 按钮 -- */
    .btn { padding: 12px 20px; font-size: 14px; }
    .btn-sm { padding: 8px 14px; font-size: 13px; }

    /* -- 快捷操作自动换行 -- */
    .card-body[style*="display:flex"] { gap: 8px !important; }
    .card-body[style*="display:flex"] .btn { flex: 1; justify-content: center; min-width: auto; padding: 12px 8px; font-size: 13px; }

    /* -- 提示消息 -- */
    .flash-messages { padding: 0 16px; margin-top: 12px; }

    /* -- 登录页 -- */
    .login-box { padding: 32px 24px; }
    .login-box h1 { font-size: 24px; }
}

/* ═══════════════════════════════════════
   小屏手机适配 (≤480px)
   ═══════════════════════════════════════ */
@media (max-width: 480px) {
    .stats-grid { grid-template-columns: 1fr; gap: 10px; }
    .stat-card { padding: 14px; display: flex; justify-content: space-between; align-items: center; }
    .stat-card .stat-label { margin-bottom: 0; }
    .stat-card .stat-value { font-size: 20px; }

    .topbar .user-info { display: none; }

    .card-body[style*="display:flex"] .btn { font-size: 12px; padding: 10px 6px; }
}
