* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --primary: #2563eb;
  --primary-dark: #1e40af;
  --green: #059669;
  --red: #dc2626;
  --orange: #d97706;
  --bg: #f1f5f9;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
}
body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px;
}

/* ---------- 顶栏 ---------- */
#topbar {
  display: flex; align-items: center; justify-content: space-between;
  background: linear-gradient(90deg, #1e3a8a, #2563eb);
  color: #fff; padding: 0 24px; height: 60px;
  position: sticky; top: 0; z-index: 50;
}
.brand { font-size: 19px; font-weight: 700; letter-spacing: 1px; }
.top-controls { display: flex; align-items: center; gap: 8px; }
.top-controls label { font-size: 13px; opacity: .85; margin-left: 10px; }
.big-select {
  font-size: 15px; padding: 7px 10px; border-radius: 8px; border: none;
  background: rgba(255,255,255,.95); color: var(--text); min-width: 90px;
}
#sel-company { min-width: 180px; font-weight: 600; }
.cur-user { font-size: 13px; margin-left: 14px; opacity: .95; white-space: nowrap; }

/* 只读账号：隐藏所有录入/修改控件 */
body.role-viewer .write-only { display: none !important; }

/* 经营分析图表 */
.chart-legend { display: flex; gap: 20px; margin-top: 8px; font-size: 13px; color: var(--muted); }
.chart-legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 5px; vertical-align: -1px; }
.hbar-row { display: flex; align-items: center; gap: 10px; margin-bottom: 9px; }
.hbar-label { width: 130px; font-size: 13px; text-align: right; flex-shrink: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hbar-track { flex: 1; background: #f1f5f9; border-radius: 6px; height: 18px; }
.hbar-fill { background: #60a5fa; height: 100%; border-radius: 6px; min-width: 2px; }
.hbar-fill.green { background: #34d399; }
.hbar-val { width: 110px; font-size: 13px; font-variant-numeric: tabular-nums; flex-shrink: 0; }

.logout-btn {
  margin-left: 12px; padding: 7px 14px; border: 1px solid rgba(255,255,255,.5);
  background: transparent; color: #fff; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.logout-btn:hover { background: rgba(255,255,255,.15); }

/* 登录页 */
#login-mask {
  position: fixed; inset: 0; z-index: 200;
  background: linear-gradient(160deg, #0f2a6b 0%, #1e3a8a 45%, #2563eb 100%);
  display: flex; align-items: center; justify-content: center;
}
#login-mask::before {
  content: ""; position: absolute; width: 560px; height: 560px; border-radius: 50%;
  background: radial-gradient(circle, rgba(96,165,250,.28), transparent 65%);
  top: -180px; right: -120px;
}
.login-card {
  position: relative; background: #fff; border-radius: 22px; padding: 42px 46px 30px;
  width: 400px; box-shadow: 0 24px 70px rgba(2,12,40,.45); text-align: center;
}
.login-logo {
  width: 68px; height: 68px; margin: -76px auto 14px; border-radius: 20px;
  background: linear-gradient(135deg, #2563eb, #1e40af); font-size: 34px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 10px 24px rgba(37,99,235,.45);
}
.login-card h2 { font-size: 24px; letter-spacing: 6px; margin-bottom: 6px; }
.login-card p { color: var(--muted); font-size: 13px; letter-spacing: 2px; margin-bottom: 26px; }
.login-field {
  display: flex; align-items: center; gap: 10px; border: 1.5px solid #e2e8f0;
  border-radius: 12px; padding: 0 14px; margin-bottom: 14px; background: #f8fafc;
  transition: border-color .15s, background .15s;
}
.login-field:focus-within { border-color: var(--primary); background: #fff; box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.login-icon { font-size: 16px; opacity: .75; }
.login-field input {
  flex: 1; border: none; outline: none; background: transparent;
  font-size: 15.5px; padding: 13px 0; letter-spacing: 1px;
}
.login-err { color: var(--red); font-size: 13px; min-height: 20px; margin-bottom: 4px; }
.login-submit {
  width: 100%; padding: 13px; font-size: 16px; letter-spacing: 8px; border-radius: 12px;
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
}
.login-submit:disabled { opacity: .7; cursor: wait; }
.login-foot { margin-top: 18px; font-size: 12px; color: #94a3b8; }
.login-card.shake { animation: shake .4s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-9px); }
  40%, 80% { transform: translateX(9px); }
}

/* 用户管理 */
.user-row {
  display: flex; align-items: center; gap: 14px; padding: 13px 6px;
  border-bottom: 1px solid var(--border);
}
.user-row:last-child { border-bottom: none; }
.user-row.user-off { opacity: .5; }
.avatar {
  width: 42px; height: 42px; border-radius: 50%; color: #fff; font-size: 18px;
  font-weight: 700; display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 15px; font-weight: 600; margin-bottom: 3px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.user-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; }
.user-actions select {
  font-size: 13px; padding: 5px 8px; border: 1px solid #cbd5e1; border-radius: 7px;
}

/* ---------- 布局 ---------- */
#layout { display: flex; min-height: calc(100vh - 60px); }
#sidebar {
  width: 170px; background: #fff; border-right: 1px solid var(--border);
  padding: 16px 10px; flex-shrink: 0;
}
#sidebar a {
  display: block; padding: 12px 14px; margin-bottom: 4px; border-radius: 10px;
  color: var(--text); text-decoration: none; cursor: pointer;
  font-size: 15.5px; transition: background .15s;
}
#sidebar a:hover { background: #eff6ff; }
#sidebar a.active { background: var(--primary); color: #fff; font-weight: 600; }
#main { flex: 1; padding: 24px 28px; max-width: 1280px; }

/* ---------- 通用组件 ---------- */
h2.page-title { font-size: 22px; margin-bottom: 6px; }
p.page-desc { color: var(--muted); margin-bottom: 18px; font-size: 14px; }
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 3px rgba(0,0,0,.04);
}
.card h3 { font-size: 16px; margin-bottom: 14px; }
.grid { display: grid; gap: 14px; }
.grid.c4 { grid-template-columns: repeat(4, 1fr); }
.grid.c3 { grid-template-columns: repeat(3, 1fr); }
.grid.c2 { grid-template-columns: repeat(2, 1fr); }

.stat {
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px 20px;
}
.stat .label { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.stat .value { font-size: 24px; font-weight: 700; }
.stat .value.green { color: var(--green); }
.stat .value.red { color: var(--red); }
.stat .value.orange { color: var(--orange); }
.stat .sub { font-size: 12px; color: var(--muted); margin-top: 4px; }

/* 表单 */
.form-row { display: flex; flex-wrap: wrap; gap: 14px; margin-bottom: 14px; }
.field { display: flex; flex-direction: column; gap: 5px; }
.field label { font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  font-size: 15px; padding: 9px 11px; border: 1px solid #cbd5e1;
  border-radius: 8px; min-width: 130px; background: #fff;
}
.field input:focus, .field select:focus { outline: 2px solid #93c5fd; border-color: var(--primary); }
.field.wide input { min-width: 220px; }
.check-field { display: flex; align-items: center; gap: 6px; padding-top: 22px; }
.check-field input { width: 18px; height: 18px; }

.btn {
  display: inline-block; padding: 10px 22px; font-size: 15px; border: none;
  border-radius: 9px; cursor: pointer; background: var(--primary); color: #fff;
  font-weight: 600; transition: background .15s;
}
.btn:hover { background: var(--primary-dark); }
.btn.secondary { background: #e2e8f0; color: var(--text); }
.btn.secondary:hover { background: #cbd5e1; }
.btn.green { background: var(--green); }
.btn.danger { background: var(--red); }
.btn.small { padding: 5px 12px; font-size: 13px; border-radius: 7px; }
.btn.ghost { background: transparent; color: var(--primary); border: 1px solid var(--primary); }

/* 表格 */
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list th {
  text-align: left; padding: 9px 10px; background: #f8fafc; color: var(--muted);
  font-weight: 600; border-bottom: 2px solid var(--border); white-space: nowrap;
}
table.list td { padding: 9px 10px; border-bottom: 1px solid var(--border); }
table.list tr:hover td { background: #f8fafc; }
table.list td.num, table.list th.num { text-align: right; font-variant-numeric: tabular-nums; }
table.list input { font-size: 14px; padding: 5px 7px; border: 1px solid #cbd5e1; border-radius: 6px; width: 100px; }

.tag { display: inline-block; padding: 2px 9px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.tag.ok { background: #d1fae5; color: #065f46; }
.tag.warn { background: #fef3c7; color: #92400e; }
.tag.bad { background: #fee2e2; color: #991b1b; }
.tag.info { background: #dbeafe; color: #1e40af; }

/* 报表 */
table.report { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.report th, table.report td { border: 1px solid #cbd5e1; padding: 6px 9px; }
table.report th { background: #eff6ff; }
table.report td.num { text-align: right; font-variant-numeric: tabular-nums; }
table.report td.sec { font-weight: 700; background: #f8fafc; }
table.report tr.total td { font-weight: 700; background: #fefce8; }

/* 提示 */
.hint {
  background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af;
  padding: 12px 16px; border-radius: 10px; font-size: 13.5px; margin-bottom: 16px;
  line-height: 1.7;
}
.hint.warn { background: #fffbeb; border-color: #fde68a; color: #92400e; }

#toast {
  position: fixed; bottom: 30px; left: 50%; transform: translateX(-50%);
  background: #1e293b; color: #fff; padding: 12px 26px; border-radius: 10px;
  font-size: 15px; opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 99;
}
#toast.show { opacity: 1; }
#toast.error { background: var(--red); }

.tabs { display: flex; gap: 8px; margin-bottom: 18px; }
.tabs button {
  padding: 9px 20px; border-radius: 20px; border: 1px solid var(--border);
  background: #fff; font-size: 14.5px; cursor: pointer;
}
.tabs button.active { background: var(--primary); color: #fff; border-color: var(--primary); font-weight: 600; }

.empty { text-align: center; color: var(--muted); padding: 30px; font-size: 14px; }
.muted { color: var(--muted); font-size: 13px; }
.money { font-variant-numeric: tabular-nums; }
.pos { color: var(--green); font-weight: 600; }
.neg { color: var(--red); font-weight: 600; }

/* 报表穿透 */
a.drill { color: var(--primary); cursor: pointer; text-decoration: underline dotted; text-underline-offset: 3px; }
a.drill:hover { background: #dbeafe; border-radius: 4px; }
#drill-mask {
  position: fixed; inset: 0; z-index: 150; background: rgba(15,23,42,.5);
  display: flex; align-items: center; justify-content: center; padding: 30px;
}
.drill-box {
  background: #fff; border-radius: 16px; width: min(860px, 94vw); max-height: 82vh;
  display: flex; flex-direction: column; box-shadow: 0 24px 70px rgba(2,12,40,.4);
}
.drill-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.drill-body { padding: 12px 20px 20px; overflow-y: auto; }

/* 期初余额网格 */
.opening-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 24px; }
.opening-grid h4 { margin: 8px 0; font-size: 15px; }
.ob-row { display: flex; align-items: center; justify-content: space-between; padding: 4px 0; }
.ob-row label { font-size: 14px; }
.ob-row input { width: 140px; text-align: right; padding: 6px 8px; border: 1px solid #cbd5e1; border-radius: 6px; }

@media (max-width: 900px) {
  .grid.c4 { grid-template-columns: repeat(2, 1fr); }
  #sidebar { width: 130px; }
}
