/* 青雀进销存 Web 版 —— 全局样式
   说明：本地样式，不依赖 CDN（便于内网部署） */

:root {
  --c-primary: #1d6fe0;
  --c-primary-dark: #1657b3;
  --c-danger: #d64545;
  --c-ok: #2e9e5b;
  --c-warn: #e08b1d;
  --c-text: #22303c;
  --c-text-muted: #7a8896;
  --c-border: #dfe5ec;
  --c-bg: #f4f6f9;
  --c-panel: #ffffff;
  --c-sidebar: #1f2b3a;
  --c-sidebar-hover: #2c3d52;
  --radius: 6px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: "Microsoft YaHei", "PingFang SC", "Hiragino Sans GB",
               system-ui, -apple-system, sans-serif;
  font-size: 14px;
  color: var(--c-text);
  background: var(--c-bg);
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef2f7; padding: 1px 5px; border-radius: 3px; font-size: 12px; }

/* ================= 布局 ================= */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 210px;
  flex: 0 0 210px;
  background: var(--c-sidebar);
  color: #c8d3e0;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  transition: width .18s ease, flex-basis .18s ease;
}

/* ---- 整体收缩态：只留窄条 ---- */
.layout.sidebar-collapsed .sidebar { width: 0; flex-basis: 0; }
.layout.sidebar-collapsed .sidebar .brand,
.layout.sidebar-collapsed .sidebar .nav { opacity: 0; pointer-events: none; }

.brand {
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  display: flex; flex-direction: column; gap: 2px;
  position: relative;
  transition: opacity .15s ease;
}
.brand-name { font-size: 16px; font-weight: 700; color: #fff; }
.brand-ver { font-size: 11px; color: #7d8ea3; }

/* 品牌区右下角的收起按钮 */
.sidebar-toggle {
  position: absolute; right: 8px; top: 12px;
  width: 22px; height: 22px; padding: 0;
  border: none; border-radius: 3px;
  background: rgba(255,255,255,.08); color: #a9b8c9;
  font-size: 13px; line-height: 1; cursor: pointer;
}
.sidebar-toggle:hover { background: rgba(255,255,255,.18); color: #fff; }

.nav { padding: 8px 0 24px; transition: opacity .15s ease; }

/* ---- 顶级独立菜单项 ---- */
.nav-item.nav-top {
  display: block;
  padding: 9px 18px;
  color: #dbe4ee;
  font-size: 14px;
  font-weight: 600;
  border-left: 3px solid transparent;
}
.nav-item.nav-top:hover { background: var(--c-sidebar-hover); color: #fff;
                          text-decoration: none; }
.nav-item.nav-top.active {
  background: var(--c-sidebar-hover);
  border-left-color: var(--c-primary);
  color: #fff;
}

/* ---- 可折叠分组 ---- */
.nav-group { margin-bottom: 2px; }

.nav-group-title {
  width: 100%;
  display: flex; align-items: center; gap: 7px;
  padding: 9px 16px;
  border: none; background: none; cursor: pointer;
  color: #9fb0c4;
  font-size: 13px; font-family: inherit; font-weight: 600;
  text-align: left;
}
.nav-group-title:hover { background: rgba(255,255,255,.05); color: #dbe4ee; }

.nav-group-arrow {
  display: inline-block; width: 12px; font-size: 10px;
  transition: transform .16s ease;
}
.nav-group.open .nav-group-arrow { transform: rotate(90deg); }

.nav-group-name { flex: 1; }

.nav-group-count {
  font-size: 10px; color: #6d8098;
  background: rgba(255,255,255,.07);
  padding: 1px 6px; border-radius: 8px;
}

/* 子项容器：默认收缩（高度 0），展开时显示 */
.nav-group-items {
  max-height: 0;
  overflow: hidden;
  transition: max-height .2s ease;
}
.nav-group.open .nav-group-items { max-height: 900px; }

.nav-item {
  display: block;
  padding: 7px 16px 7px 34px;
  color: #c8d3e0;
  font-size: 13px;
  border-left: 3px solid transparent;
}
.nav-item:hover { background: var(--c-sidebar-hover); text-decoration: none;
                  color: #fff; }
.nav-item.active {
  background: var(--c-sidebar-hover);
  border-left-color: var(--c-primary);
  color: #fff;
  font-weight: 600;
}

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 52px;
  background: #fff;
  border-bottom: 1px solid var(--c-border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 10;
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.topbar-menu { display: none; }
.page-title { font-size: 15px; font-weight: 600; }

/* 侧边栏收起后，顶栏出现 ☰ 按钮 */
.layout.sidebar-collapsed .topbar-menu { display: inline-flex; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.user-info { font-size: 13px; }
.user-role {
  font-size: 11px; color: var(--c-text-muted);
  background: #eef2f7; padding: 2px 6px; border-radius: 3px; margin-left: 4px;
}

.content { padding: 18px 20px 40px; }

/* ================= 卡片 / 面板 ================= */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.card {
  background: var(--c-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 16px;
}
.card-label { font-size: 12px; color: var(--c-text-muted); margin-bottom: 8px; }
.card-value { font-size: 24px; font-weight: 700; color: var(--c-primary); }
.card-sub { font-size: 12px; color: var(--c-text-muted); margin-top: 6px; }

.panel {
  background: var(--c-panel);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  margin-bottom: 16px;
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--c-border);
  background: #fafbfc;
  gap: 12px;
  flex-wrap: wrap;
}
.panel-title { font-weight: 600; }
.panel-body { padding: 16px; }
.panel-form { max-width: 720px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 900px) { .grid-2 { grid-template-columns: 1fr; } }

/* ================= 表格 ================= */
.table { width: 100%; border-collapse: collapse; }
.table th, .table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--c-border);
  text-align: left;
  vertical-align: middle;
}
.table th {
  background: #f7f9fb;
  font-size: 12px;
  font-weight: 600;
  color: var(--c-text-muted);
  white-space: nowrap;
}
.table tbody tr:hover { background: #f9fbfd; }
.table .empty { text-align: center; color: var(--c-text-muted); padding: 26px; }
.col-ops { white-space: nowrap; }
.col-ops > * { margin-right: 4px; }
.col-perm { width: 62px; text-align: center !important; }
.table-perm th, .table-perm td { padding: 6px 10px; }

/* ================= 表单 ================= */
.field { margin-bottom: 14px; }
.field label { display: block; margin-bottom: 5px; font-size: 13px; font-weight: 500; }
.field .req { color: var(--c-danger); }
.field .hint { font-size: 12px; color: var(--c-text-muted); margin-top: 4px; }

input[type=text], input[type=password], input[type=number],
input[type=date], select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 2px rgba(29,111,224,.12);
}
input[type=checkbox] { width: auto; }

.inline-form { display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.inline-form input[type=text] { width: 160px; }
.check-inline { font-size: 13px; display: inline-flex; align-items: center; gap: 4px; }

.form-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; }
.form-actions-sticky {
  position: sticky; bottom: 0;
  background: #fff; border-top: 1px solid var(--c-border);
  padding: 12px 16px; margin: 0 -16px -16px;
}

/* ================= 按钮 ================= */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 7px 14px;
  border: 1px solid var(--c-border);
  border-radius: 4px;
  background: #fff;
  color: var(--c-text);
  font-size: 13px;
  font-family: inherit;
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { background: #f2f5f9; text-decoration: none; }
.btn-primary { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }
.btn-primary:hover { background: var(--c-primary-dark); }
.btn-danger { color: var(--c-danger); border-color: #f0c4c4; }
.btn-danger:hover { background: #fdf2f2; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-xs { padding: 3px 8px; font-size: 12px; }
.btn-block { width: 100%; padding: 10px; font-size: 15px; }

/* ================= 标签 / 提示 ================= */
.tag {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 3px;
  font-size: 11px;
  background: #eef2f7;
  color: #4a5b6d;
  white-space: nowrap;
}
.tag-ok { background: #e6f6ec; color: var(--c-ok); }
.tag-off { background: #f2f3f5; color: #8a97a5; }
.tag-warn { background: #fdf3e2; color: var(--c-warn); }

.alert {
  padding: 10px 14px;
  border-radius: 4px;
  margin: 0 20px 14px;
  font-size: 13px;
  border: 1px solid transparent;
}
.alert-ok { background: #e9f7ef; border-color: #bfe6cf; color: #1f7a45; }
.alert-err { background: #fdecec; border-color: #f3c8c8; color: #b32f2f; }
.alert-tip { background: #eaf2fd; border-color: #c7dcf8; color: #1b5aa8; }

.muted { color: var(--c-text-muted); }
.big-warn { font-size: 18px; font-weight: 600; color: var(--c-danger); }

/* ================= 权限矩阵 ================= */
.perm-group { margin-bottom: 18px; border: 1px solid var(--c-border); border-radius: 4px; }
.perm-group-head {
  padding: 9px 12px;
  background: #f7f9fb;
  border-bottom: 1px solid var(--c-border);
  font-size: 13px;
}

/* ================= 登录 / 初始化页 ================= */
.auth-body {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #1f2b3a 0%, #2c3d52 100%);
}
.auth-card {
  width: 380px;
  background: #fff;
  border-radius: 8px;
  padding: 28px 26px 20px;
  box-shadow: 0 10px 40px rgba(0,0,0,.2);
}
.auth-card-wide { width: 440px; }
.auth-head { text-align: center; margin-bottom: 18px; }
.auth-title { font-size: 20px; font-weight: 700; color: var(--c-primary); }
.auth-sub { font-size: 12px; color: var(--c-text-muted); margin-top: 4px; }
.auth-card .alert { margin: 0 0 14px; }
.auth-foot {
  text-align: center; font-size: 11px; color: #aab6c4;
  margin-top: 16px; padding-top: 12px; border-top: 1px solid #eef2f7;
}

/* ================= Toast ================= */
.toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: #22303c; color: #fff;
  padding: 10px 20px; border-radius: 4px; font-size: 13px;
  z-index: 9999;
}

/* ================= 弹窗（B 增强） ================= */
.modal { position: fixed; inset: 0; z-index: 1000; display: flex;
         align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-mask { position: absolute; inset: 0; background: rgba(20,30,40,.45); }
.modal-box {
  position: relative;
  background: #fff; border-radius: 8px;
  width: 460px; max-width: 92vw; max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 12px 40px rgba(0,0,0,.25);
}
.modal-box.modal-lg { width: 760px; }
.modal-head {
  padding: 14px 18px; border-bottom: 1px solid var(--c-border);
  font-weight: 600; display: flex; align-items: center; justify-content: space-between;
}
.modal-close {
  border: none; background: none; font-size: 20px; line-height: 1;
  cursor: pointer; color: var(--c-text-muted); padding: 0 4px;
}
.modal-close:hover { color: var(--c-danger); }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot {
  padding: 12px 18px; border-top: 1px solid var(--c-border);
  display: flex; gap: 10px; justify-content: flex-end;
}

/* 表单两列布局（弹窗/表单页） */
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 700px) { .form-row { grid-template-columns: 1fr; } }

/* 商品图片缩略 */
.thumb { width: 42px; height: 42px; object-fit: cover; border-radius: 4px;
         border: 1px solid var(--c-border); background: #f7f9fb; }
.thumb-none { width: 42px; height: 42px; border-radius: 4px; border: 1px dashed var(--c-border);
              display: inline-flex; align-items: center; justify-content: center;
              font-size: 10px; color: #aab6c4; }

/* 表格工具条 */
.table-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; flex-wrap: wrap; margin-bottom: 12px;
}
.table-toolbar form { display: flex; align-items: center; gap: 6px; }
.table-toolbar input[type=text] { width: 200px; }

/* 分页 */
.pager { display: flex; gap: 6px; align-items: center; margin-top: 14px; }
.pager a, .pager span {
  padding: 4px 10px; border: 1px solid var(--c-border); border-radius: 4px;
  font-size: 13px; background: #fff;
}
.pager .current { background: var(--c-primary); border-color: var(--c-primary); color: #fff; }

/* 空状态 */
.empty-state { text-align: center; padding: 40px 20px; color: var(--c-text-muted); }

/* ================= 信息网格（详情页） ================= */
.info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 10px 20px;
  font-size: 13px;
}
.info-grid > div { padding: 4px 0; border-bottom: 1px dashed #eef2f7; }

/* 数字右对齐 */
.table .num, .num { text-align: right; font-variant-numeric: tabular-nums; }
.table tfoot td { background: #f7f9fb; font-weight: 600; }

/* 明细行内输入框紧凑显示 */
#itemsTable input, #itemsTable select { padding: 5px 7px; font-size: 13px; }
#itemsTable td { vertical-align: middle; }

/* 汇总条 */
.summary-bar {
  display: flex; gap: 24px; align-items: center; flex-wrap: wrap;
  padding: 10px 16px; background: #f7f9fb;
  border: 1px solid var(--c-border); border-radius: 4px; font-size: 13px;
}

/* 小标题（报表页分组） */
.sub-title {
  font-size: 13px; font-weight: 600; color: var(--c-text);
  margin: 4px 0 8px; padding-left: 8px;
  border-left: 3px solid var(--c-primary);
}

/* ================= 标签页（日志页） ================= */
.tabs {
  display: flex; gap: 4px; margin-bottom: 14px;
  border-bottom: 1px solid var(--c-border);
}
.tab {
  padding: 8px 16px; font-size: 13px;
  border: 1px solid transparent; border-bottom: none;
  border-radius: 4px 4px 0 0; color: var(--c-text-muted);
  margin-bottom: -1px;
}
.tab:hover { background: #f4f7fa; text-decoration: none; }
.tab.active {
  background: #fff; border-color: var(--c-border);
  border-bottom-color: #fff; color: var(--c-primary); font-weight: 600;
}

/* 登录页底部链接 */
.auth-link { color: #aab6c4; text-decoration: none; }
.auth-link:hover { color: var(--c-primary); text-decoration: underline; }
