/* =========================================================
   个体工商户记账系统 - 后台样式
   ========================================================= */
:root {
  --primary: #2f6bff;
  --primary-dark: #1f52d8;
  --income: #16a34a;
  --expense: #e11d48;
  --bg: #f3f5f9;
  --card: #ffffff;
  --border: #e5e9f2;
  --text: #1f2733;
  --muted: #7a8699;
  --sidebar-w: 220px;
}

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

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

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

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

.sidebar {
  width: var(--sidebar-w);
  background: #141a26;
  color: #c9d2e0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
}

.sidebar .brand {
  display: flex; align-items: center; gap: 10px;
  padding: 18px 16px;
  font-size: 17px;
  font-weight: 700;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,.08);
  letter-spacing: .5px;
}
.sidebar .brand-logo { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; flex-shrink: 0; background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.25); }
.sidebar .brand-text { line-height: 1.3; min-width: 0; }
.sidebar .brand-text small { display: block; font-size: 12px; font-weight: 400; color: #8b96a8; margin-top: 2px; letter-spacing: 0; }

.sidebar nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 11px 14px; margin: 3px 0;
  border-radius: 8px; color: #c9d2e0; font-size: 14px;
  transition: background .15s, color .15s;
}
.sidebar nav a .ico { width: 18px; text-align: center; }
.sidebar nav a:hover { background: rgba(255,255,255,.07); color:#fff; }
.sidebar nav a.active { background: var(--primary); color: #fff; }

.sidebar .foot { padding: 14px 20px; border-top: 1px solid rgba(255,255,255,.08); font-size:12px; color:#7d8799; }

.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  background: var(--card);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  height: 58px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 40;
}
.topbar .page-title { font-size: 16px; font-weight: 600; }
.topbar-left { display:flex; align-items:center; gap:12px; min-width:0; }
.menu-toggle {
  display:none;
  width:38px; height:38px; border-radius:8px; border:1px solid var(--border);
  background:#fff; color:var(--text); font-size:18px; cursor:pointer; flex-shrink:0;
  align-items:center; justify-content:center; line-height:1;
}
.menu-toggle:hover { border-color:var(--primary); color:var(--primary); }
.topbar .user { display:flex; align-items:center; gap:12px; color:var(--muted); font-size:13px; }
.topbar .user .avatar {
  width:30px; height:30px; border-radius:50%;
  background: var(--primary); color:#fff;
  display:flex; align-items:center; justify-content:center; font-size:13px; font-weight:600;
}

.content { padding: 24px; }

/* ---------- 卡片 / 统计 ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
}
.card + .card { margin-top: 20px; }
.card-title { font-size: 15px; font-weight: 600; margin-bottom: 14px; display:flex; align-items:center; justify-content:space-between; }

.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.stat {
  background: var(--card); border:1px solid var(--border); border-radius:12px; padding:18px 20px;
}
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 6px; }
.stat .value.income { color: var(--income); }
.stat .value.expense { color: var(--expense); }
.stat .sub { color: var(--muted); font-size: 12px; margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }

/* ---------- 表格 ---------- */
.table-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th, table.tbl td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.tbl thead th { background:#f8fafc; color:var(--muted); font-weight:600; font-size:13px; }
table.tbl tbody tr:hover { background: #f7f9fd; }
table.tbl .num { text-align: right; font-variant-numeric: tabular-nums; }
table.tbl .income { color: var(--income); }
table.tbl .expense { color: var(--expense); }
table.tbl .ops a { margin-right: 10px; font-size: 13px; }

.badge { display:inline-block; padding:2px 9px; border-radius:20px; font-size:12px; }
.badge.income { background:#e7f6ec; color:var(--income); }
.badge.expense { background:#fdeaea; color:var(--expense); }
.badge.gray { background:#eef1f6; color:var(--muted); }

/* ---------- 表单 ---------- */
.form-group { margin-bottom: 16px; }
.form-group label { display:block; margin-bottom:6px; color:#3a4657; font-size:13px; font-weight:500; }
.form-group .hint { color: var(--muted); font-size:12px; margin-top:4px; }

input[type=text], input[type=password], input[type=number], input[type=date], select, textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 14px;
  color: var(--text);
  background: #fff;
  transition: border-color .15s, box-shadow .15s;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(47,107,255,.12);
}
textarea { resize: vertical; min-height: 80px; }

.form-inline { display:flex; gap:10px; flex-wrap:wrap; align-items:center; }
.form-inline input[type=text], .form-inline input[type=date], .form-inline select { width: auto; min-width: 130px; }

/* ---------- 按钮 ---------- */
.btn {
  display:inline-flex; align-items:center; justify-content:center; gap:6px;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid transparent;
  font-size: 14px;
  cursor: pointer;
  transition: background .15s, opacity .15s;
  font-family: inherit;
  line-height: 1.4;
}
.btn-primary { background: var(--primary); color:#fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background:#fff; color:var(--text); border-color:var(--border); }
.btn-ghost:hover { border-color:var(--primary); color:var(--primary); }
.btn-danger { background: var(--expense); color:#fff; }
.btn-danger:hover { opacity:.9; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-danger-text { color: var(--expense); background:none; border:none; cursor:pointer; font-size:13px; padding:0; font-family:inherit; }
.btn-danger-text:hover { text-decoration:underline; }

/* ---------- 页脚 / 分页 ---------- */
.footer { padding: 18px 24px; color: var(--muted); font-size: 12px; border-top:1px solid var(--border); margin-top:auto; }

.pagination { display:flex; gap:6px; margin-top:16px; flex-wrap:wrap; align-items:center; }
.pagination a, .pagination span {
  padding: 6px 12px; border:1px solid var(--border); border-radius:6px;
  color:var(--text); font-size:13px;
}
.pagination .current { background:var(--primary); border-color:var(--primary); color:#fff; }
.pagination .disabled { color:#c0c6d0; pointer-events:none; }

/* ---------- 登录页 ---------- */
.login-page {
  min-height: 100vh;
  display:flex; align-items:center; justify-content:center;
  padding: 24px;
  background: linear-gradient(135deg, #1f3a8a 0%, #2f6bff 100%);
}
.login-card {
  display: flex; width: 860px; max-width: 96vw; min-height: 500px;
  background: #fff; border-radius: 18px; overflow: hidden;
  box-shadow: 0 24px 70px rgba(0,0,0,.30);
}
/* 左侧品牌区 */
.login-left {
  flex: 1.1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 6px; padding: 40px 32px; text-align: center; color: #fff;
  background: linear-gradient(160deg, #2b2f77 0%, #4b56cc 100%);
}
.login-left .login-logo {
  width: 116px; height: 116px; border-radius: 50%; object-fit: cover;
  background: #fff; box-shadow: 0 10px 26px rgba(0,0,0,.25); margin-bottom: 20px;
}
.login-left h1 { font-size: 28px; margin-bottom: 6px; }
.login-left .sub { font-size: 14px; opacity: .92; }
/* 右侧表单区 */
.login-right {
  flex: 1; padding: 52px 46px; display: flex; flex-direction: column; justify-content: center;
}
.login-right .login-head { font-size: 26px; font-weight: 700; margin-bottom: 6px; color: #1f2937; }
.login-right .form-group label { color: #374151; }
.login-right .btn { width: 100%; margin-top: 8px; padding: 12px; font-size: 15px; }

/* 移动端：上下堆叠 */
@media (max-width: 720px) {
  .login-card { flex-direction: column; min-height: 0; }
  .login-left { padding: 32px 24px 24px; }
  .login-left .login-logo { width: 84px; height: 84px; }
  .login-right { padding: 28px 26px 36px; }
}

/* ---------- 提示 ---------- */
.msg-tip {
  position: fixed; top: 22px; left: 50%; transform: translateX(-50%);
  padding: 11px 22px; border-radius: 8px; color:#fff; font-size:14px;
  z-index: 9999; box-shadow: 0 8px 24px rgba(0,0,0,.18);
  display:none;
}
.msg-tip.ok { background:#16a34a; }
.msg-tip.err { background:#e11d48; }

.empty { text-align:center; color:var(--muted); padding:40px 0; }

/* 图表容器 */
.chart { width:100%; height:320px; }
.chart-sm { width:100%; height:300px; }

/* 分类管理 */
.cat-group { margin-bottom: 8px; }
.cat-row {
  display:flex; align-items:center; gap:10px;
  padding:8px 10px; border:1px solid var(--border); border-radius:8px; margin-bottom:8px;
  background:#fbfcfe;
}
.cat-row .name { flex:1; font-weight:500; }
.cat-row .sort { color:var(--muted); font-size:12px; width:70px; }
.cat-row form { display:flex; gap:8px; flex:1; align-items:center; }
.cat-row .status { font-size:12px; }

/* 滚动条美化 */
::-webkit-scrollbar { width:8px; height:8px; }
::-webkit-scrollbar-thumb { background:#cdd4e0; border-radius:4px; }
::-webkit-scrollbar-track { background:transparent; }

@media (max-width: 900px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2, .grid-2-1 { grid-template-columns: 1fr; }
  .sidebar { width: 64px; }
  .sidebar .brand { justify-content: center; padding: 14px 8px; }
  .sidebar .brand .brand-text, .sidebar nav a .txt, .sidebar .foot { display:none; }
  .main { margin-left: 64px; }
}

/* ---------- 头像 / 凭证 / 上传 ---------- */
.topbar .user .avatar-img { width:30px; height:30px; border-radius:50%; object-fit:cover; border:1px solid var(--border); }
.avatar-img-sm { width:36px; height:36px; border-radius:50%; object-fit:cover; border:1px solid var(--border); vertical-align:middle; }
.avatar-img-lg { width:76px; height:76px; border-radius:50%; object-fit:cover; border:2px solid var(--border); }
.muted { color: var(--muted); }

.thumb { width:46px; height:46px; border-radius:6px; object-fit:cover; border:1px solid var(--border); vertical-align:middle; }
.thumb-num { display:inline-block; min-width:46px; text-align:center; padding:0 6px; height:46px; line-height:46px; background:#eef1f6; color:var(--muted); border-radius:6px; font-size:13px; cursor:pointer; margin-left:4px; vertical-align:middle; }
.thumb-num:hover { background:#dfe5ee; }

.file-input { font-size:13px; }
.upload-preview { display:flex; flex-wrap:wrap; gap:12px; margin-top:12px; }
.up-item { position:relative; width:78px; height:78px; }
.up-item img { width:78px; height:78px; border-radius:8px; object-fit:cover; border:1px solid var(--border); cursor:pointer; display:block; }
.up-remove { position:absolute; top:-7px; right:-7px; width:20px; height:20px; border-radius:50%; background:#e11d48; color:#fff; border:none; cursor:pointer; font-size:14px; line-height:1; display:flex; align-items:center; justify-content:center; padding:0; }
.up-remove:hover { background:#b91339; }

#lightbox { position:fixed; inset:0; background:rgba(0,0,0,.74); display:none; align-items:center; justify-content:center; z-index:10000; cursor:zoom-out; }
#lightbox.show { display:flex; }
#lightbox img { max-width:92vw; max-height:92vh; border-radius:6px; box-shadow:0 10px 40px rgba(0,0,0,.5); }

/* 手机端抽屉菜单遮罩 */
.overlay { display:none; position:fixed; inset:0; background:rgba(0,0,0,.45); z-index:49; }
.overlay.show { display:block; }

/* =========================================================
   手机端（≤768px）适配：侧栏改为抽屉式
   ========================================================= */
@media (max-width: 768px) {
  .menu-toggle { display:inline-flex; }

  .sidebar {
    width: var(--sidebar-w);
    transform: translateX(-100%);
    transition: transform .26s ease;
    box-shadow: 0 0 40px rgba(0,0,0,.3);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar .brand .brand-text, .sidebar nav a .txt, .sidebar .foot { display: block; }

  .main { margin-left: 0; }

  .topbar { padding: 0 14px; height: 52px; }
  .topbar .user { gap: 8px; }
  .topbar .user-name, .topbar .user .user-link { display: none; }

  .content { padding: 14px; }
  .footer { padding: 14px; }
  .card { padding: 16px; }

  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat { padding: 14px; }
  .stat .value { font-size: 22px; }
  .grid-2, .grid-2-1 { grid-template-columns: 1fr; gap: 14px; }

  .btn { padding: 11px 16px; }
  .pagination a, .pagination span { padding: 8px 12px; }
  .form-inline input[type=text], .form-inline input[type=date], .form-inline select { width: 100%; min-width: 0; }
  .cat-row form { flex-wrap: wrap; }
  .upload-preview { gap: 10px; }
  .up-item, .up-item img { width: 64px; height: 64px; }
  .thumb { width: 40px; height: 40px; }
  .thumb-num { min-width: 40px; height: 40px; line-height: 40px; font-size: 12px; }

  .chart, .chart-sm { height: 260px; }
}
@media (max-width: 380px) {
  .stat-grid { grid-template-columns: 1fr; }
}
