/* ===== 全局 ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

:root {
    --primary: #4f46e5;
    --primary-light: #e0e0ff;
    --primary-dark: #3730a3;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --bg: #f5f5f5;
    --card-bg: #ffffff;
    --text: #1f2937;
    --text-light: #6b7280;
    --border: #e5e7eb;
    --radius: 8px;
    --shadow: 0 1px 3px rgba(0,0,0,0.1);
    --shadow-md: 0 4px 6px rgba(0,0,0,0.07);
}

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

/* ===== 导航栏 ===== */
.navbar {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    padding: 0 24px;
    height: 56px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    position: sticky;
    top: 0;
    z-index: 100;
}
.navbar h1 { font-size: 18px; font-weight: 600; }
.navbar .nav-tabs {
    margin-left: 40px;
    display: flex;
    gap: 4px;
}
.nav-tab {
    padding: 6px 16px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    font-size: 14px;
    opacity: 0.8;
}
.nav-tab:hover { opacity: 1; background: rgba(255,255,255,0.15); }
.nav-tab.active { opacity: 1; background: rgba(255,255,255,0.2); font-weight: 600; }
.navbar .spacer { flex: 1; }

/* ===== 主容器 ===== */
.container { max-width: 1280px; margin: 0 auto; padding: 20px; }

/* ===== 统计卡片 ===== */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
    display: flex;
    align-items: center;
    gap: 16px;
}
.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex; align-items: center; justify-content: center;
    font-size: 22px;
}
.stat-info .stat-value { font-size: 24px; font-weight: 700; }
.stat-info .stat-label { font-size: 12px; color: var(--text-light); }

/* ===== 工具栏 ===== */
.toolbar {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 12px 16px;
    margin-bottom: 16px;
    box-shadow: var(--shadow);
    display: flex;
    gap: 12px;
    align-items: center;
    flex-wrap: wrap;
}
.toolbar input, .toolbar select {
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
}
.toolbar input:focus, .toolbar select:focus { border-color: var(--primary); }
.toolbar input[type="text"] { min-width: 200px; }
.spacer { flex: 1; }

/* ===== 分段切换（按供应商 / 按原料） ===== */
.seg-toggle {
    display: inline-flex;
    background: #f1f3f5;
    border-radius: 8px;
    padding: 3px;
    gap: 2px;
}
.seg-btn {
    border: none;
    background: transparent;
    padding: 7px 16px;
    border-radius: 6px;
    font-size: 13px;
    color: #6b7280;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}
.seg-btn:hover { color: #1f2937; }
.seg-btn.active {
    background: #fff;
    color: #4f46e5;
    font-weight: 600;
    box-shadow: 0 1px 3px rgba(0,0,0,0.08);
}

/* ===== 按钮 ===== */
.btn {
    padding: 8px 16px;
    border: none;
    border-radius: 6px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.2s;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { opacity: 0.9; }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary); }

/* ===== 表格 ===== */
.table-wrap {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow-x: auto;
}
table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}
th {
    background: #f9fafb;
    padding: 10px 12px;
    text-align: left;
    font-weight: 600;
    color: var(--text-light);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
    position: sticky;
    top: 0;
}
td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}
tr:hover { background: #f9fafb; }
/* 原始配方表：严格保留 Excel 单元格边框，所有单元格均用 td 渲染 */
.raw-table { font-size: 12px; border-collapse: collapse; }
.raw-table td { border: 1px solid #e5e7eb; padding: 5px 8px; vertical-align: top; line-height: 1.5; }
.raw-table tr:nth-child(odd) td { background: #fafbfc; }
.price-cell { font-weight: 600; color: var(--primary); }
.category-tag {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 4px;
    font-size: 11px;
    font-weight: 500;
    background: var(--primary-light);
    color: var(--primary-dark);
}

/* ===== 弹窗 ===== */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,0.4);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}
.modal-overlay.show { display: flex; }
.modal {
    background: #fff;
    border-radius: 12px;
    width: 600px;
    max-width: 90vw;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}
.modal-header {
    padding: 16px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.modal-header h3 { font-size: 16px; }
.modal-close { cursor: pointer; font-size: 20px; color: var(--text-light); background: none; border: none; }
.modal-body { padding: 24px; }
.modal-footer {
    padding: 16px 24px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    justify-content: flex-end;
}

/* ===== 表单 ===== */
.form-group { margin-bottom: 16px; }
.form-group label {
    display: block;
    margin-bottom: 6px;
    font-weight: 500;
    font-size: 13px;
}
.form-group input, .form-group select, .form-group textarea {
    width: 100%;
    padding: 8px 12px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: 14px;
    outline: none;
    transition: border-color 0.2s;
    font-family: inherit;
}
.form-group input:focus, .form-group select:focus, .form-group textarea:focus { border-color: var(--primary); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row .form-group { margin-bottom: 16px; }

/* ===== 价格历史 ===== */
.price-history-list {
    max-height: 300px;
    overflow-y: auto;
}
.price-history-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
}
.price-history-item .date { color: var(--text-light); font-size: 12px; }
.price-history-item .price { font-weight: 600; color: var(--primary); }

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 24px;
    right: 24px;
    padding: 12px 24px;
    border-radius: 8px;
    color: #fff;
    font-size: 14px;
    z-index: 2000;
    box-shadow: 0 4px 12px rgba(0,0,0,0.2);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }

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

/* ===== 首页：最近查看 ===== */
.home-header {
    display: flex;
    align-items: baseline;
    gap: 12px;
    margin-bottom: 20px;
}
.home-header h2 { font-size: 20px; font-weight: 700; }

.recent-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 16px;
}
.recent-card {
    background: var(--card-bg);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s;
    border: 1px solid transparent;
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.recent-card:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--primary);
    transform: translateY(-2px);
}
.recent-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
}
.recent-card-header strong { font-size: 16px; }
.recent-card-body {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.recent-card-row {
    display: flex;
    align-items: baseline;
    gap: 8px;
    font-size: 13px;
}
.recent-card-row .label {
    color: var(--text-light);
    font-size: 11px;
    min-width: 48px;
    flex-shrink: 0;
}
.recent-card-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

/* ===== 详情弹窗 ===== */
.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
}
.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
}
.detail-label {
    font-size: 11px;
    color: var(--text-light);
    font-weight: 500;
}

/* ===== 配方原料超链接 ===== */
.ingredient-link {
    color: var(--primary);
    text-decoration: none;
    cursor: pointer;
    border-bottom: 1px dashed transparent;
    transition: all 0.2s;
}
.ingredient-link:hover {
    color: var(--primary-dark);
    border-bottom-color: var(--primary);
}
.ingredient-link strong { color: inherit; }

/* ===== 原料高亮行（从配方跳转后） ===== */
.highlight-row {
    animation: highlight-fade 3s ease-out;
}
@keyframes highlight-fade {
    0%   { background-color: #fef3c7; }
    70%  { background-color: #fef3c7; }
    100% { background-color: transparent; }
}

/* ===== 返回配方提示横幅 ===== */
.formula-return-banner {
    background: linear-gradient(135deg, #eef2ff, #e0e0ff);
    border: 1px solid var(--primary-light);
    border-radius: var(--radius);
    padding: 10px 16px;
    margin-bottom: 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    font-size: 13px;
    color: var(--primary-dark);
    box-shadow: var(--shadow);
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    .navbar { flex-wrap: wrap; height: auto; padding: 12px; }
    .navbar .nav-tabs { margin-left: 0; margin-top: 8px; }
    .form-row { grid-template-columns: 1fr; }
    .toolbar { flex-direction: column; align-items: stretch; }
    .detail-grid { grid-template-columns: 1fr; }
    .recent-grid { grid-template-columns: 1fr; }
}

/* ===== 配方管理：左侧标签快速导航 ===== */
.formula-layout { display: flex; gap: 20px; align-items: flex-start; }
.formula-nav {
    flex: 0 0 200px;
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px 12px;
    box-shadow: var(--shadow);
    position: sticky;
    top: 76px;
    max-height: calc(100vh - 96px);
    overflow-y: auto;
}
.formula-nav-title {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-light);
    margin-bottom: 12px;
    padding: 0 8px;
}
.formula-nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 9px 10px;
    border: none;
    background: transparent;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    color: var(--text);
    text-align: left;
    transition: all 0.2s;
    font-family: inherit;
}
.formula-nav-item:hover { background: #f3f4f6; }
.formula-nav-item.active { background: var(--primary-light); color: var(--primary-dark); font-weight: 600; }
.formula-nav-item .dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.formula-nav-item .label { flex: 1; }
.formula-nav-item .count {
    font-size: 11px;
    color: var(--text-light);
    background: #f3f4f6;
    padding: 1px 7px;
    border-radius: 10px;
}
.formula-nav-item.active .count { background: #fff; color: var(--primary-dark); }
.formula-nav-group {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-light);
    letter-spacing: 0.05em;
    margin: 12px 8px 4px;
    padding-top: 8px;
    border-top: 1px solid var(--border, #eef0f3);
}
.formula-nav-group:first-of-type { border-top: none; padding-top: 0; }
.formula-main { flex: 1; min-width: 0; }

@media (max-width: 768px) {
    .formula-layout { flex-direction: column; }
    .formula-nav { flex: none; width: 100%; position: static; max-height: none; }
}

/* ===== 原料资料库 ===== */
.materials-layout { display: flex; gap: 16px; align-items: flex-start; }
.materials-sidebar {
    width: 240px; flex: none; background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e5e7eb); border-radius: var(--radius, 8px);
    padding: 10px; max-height: calc(100vh - 140px); overflow-y: auto;
}
.materials-sidebar-header {
    display: flex; align-items: center; justify-content: space-between;
    font-weight: 600; padding: 4px 6px 10px; border-bottom: 1px solid var(--border, #e5e7eb);
}
.materials-folder-list { margin-top: 6px; }
.folder-item {
    display: flex; align-items: center; justify-content: space-between;
    padding: 8px 10px; border-radius: 6px; cursor: pointer; color: var(--text, #1f2937);
}
.folder-item:hover { background: #f3f4f6; }
.folder-item.active { background: var(--primary-light, #e0e0ff); color: var(--primary-dark, #3730a3); font-weight: 600; }
.folder-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.folder-count {
    font-size: 11px; color: var(--text-light, #6b7280); background: #f3f4f6;
    padding: 1px 8px; border-radius: 10px; margin-left: 8px; flex: none;
}
.folder-item.active .folder-count { background: #fff; color: var(--primary-dark, #3730a3); }
.materials-main { flex: 1; min-width: 0; }
.material-count { font-size: 13px; color: var(--text-light, #6b7280); }
.materials-list { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.material-card {
    display: flex; align-items: center; gap: 14px; background: var(--card-bg, #fff);
    border: 1px solid var(--border, #e5e7eb); border-radius: var(--radius, 8px);
    padding: 12px 14px; transition: box-shadow .15s, border-color .15s;
}
.material-card:hover { box-shadow: var(--shadow-md, 0 4px 6px rgba(0,0,0,.07)); border-color: var(--primary-light, #e0e0ff); }
.material-icon { font-size: 28px; flex: none; width: 36px; text-align: center; }
.material-info { flex: 1; min-width: 0; }
.material-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.material-meta { display: flex; gap: 10px; flex-wrap: wrap; font-size: 12px; color: var(--text-light, #6b7280); margin-top: 4px; }
.material-badge {
    background: var(--primary-light, #e0e0ff); color: var(--primary-dark, #3730a3);
    padding: 1px 8px; border-radius: 10px; font-size: 11px;
}
.material-actions { display: flex; gap: 6px; flex: none; }
.loading { padding: 20px; color: var(--text-light, #6b7280); }

@media (max-width: 768px) {
    .materials-layout { flex-direction: column; }
    .materials-sidebar { width: 100%; max-height: none; }
}

/* ======================== 登录遮罩 ======================== */
#login-overlay {
    position: fixed; inset: 0; z-index: 1000;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}
.login-box {
    width: 340px; max-width: 90vw; background: #fff; border-radius: 14px;
    padding: 32px 28px; box-shadow: 0 20px 50px rgba(0,0,0,.25); text-align: center;
}
.login-logo { font-size: 44px; margin-bottom: 6px; }
.login-box h2 { font-size: 18px; color: #1f2937; margin: 0 0 4px; }
.login-sub { color: #9ca3af; font-size: 13px; margin: 0 0 20px; }
.login-box input {
    width: 100%; box-sizing: border-box; padding: 11px 12px; margin-bottom: 12px;
    border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; outline: none;
}
.login-box input:focus { border-color: #6366f1; }
.login-btn { width: 100%; padding: 11px; font-size: 15px; }
.login-error { color: #dc2626; font-size: 13px; min-height: 18px; margin-bottom: 6px; }
.login-tip { color: #9ca3af; font-size: 12px; margin-top: 10px; }

/* ======================== 用户控件 ======================== */
#user-controls { display: flex; align-items: center; gap: 10px; }
.user-name { color: #fff; font-size: 13px; }
#user-controls .btn-sm {
    padding: 5px 12px; font-size: 12px; background: rgba(255,255,255,.15);
    color: #fff; border: 1px solid rgba(255,255,255,.35);
}
#user-controls .btn-sm:hover { background: rgba(255,255,255,.28); }

/* ======================== 账号管理 ======================== */
.perm-grid { display: flex; flex-wrap: wrap; gap: 14px; margin: 10px 0 16px; }
.chk { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: #374151; cursor: pointer; }
.form-row { display: flex; flex-wrap: wrap; gap: 12px; align-items: center; margin-bottom: 12px; }
.form-row input[type="text"], .form-row input[type="password"] {
    padding: 9px 11px; border: 1px solid #d1d5db; border-radius: 8px; font-size: 14px; min-width: 160px;
}


/* ===== 账号管理：三档权限（查看 / 编辑&删除 / 上传&下载） ===== */
.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; margin: 12px 0; }
.perm-block { border: 1px solid #e5e7eb; border-radius: 8px; padding: 10px 12px; background: #fff; }
.perm-block-title { font-weight: 600; margin-bottom: 6px; font-size: 13px; color: #1f2937; }
.perm-block .chk { display: block; margin: 3px 0; font-size: 13px; }
.perm-cell { white-space: nowrap; text-align: center; }
.perm-cell input[type="checkbox"] { margin: 0 2px; }
