/* =========================================================================
 * 无忧 ERP —— 样式
 * ========================================================================= */
:root {
  --green: #16a34a;
  --green-dark: #15803d;
  --green-light: #dcfce7;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --muted: #6b7280;
  --danger: #dc2626;
  --warn: #d97706;
  --primary: #16a34a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0, 0, 0, .06), 0 1px 2px rgba(0, 0, 0, .04);
  --sidebar-w: 220px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg); color: var(--text); font-size: 14px; line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--green); text-decoration: none; }
a:hover { text-decoration: none; }
code { background: #eef2f6; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* ===== 应用外壳 ===== */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: var(--sidebar-w); background: #0f172a; color: #e2e8f0; flex-shrink: 0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh;
}
.logo { display: flex; align-items: center; gap: 10px; padding: 20px 18px; font-size: 18px; font-weight: 700; color: #fff; border-bottom: 1px solid rgba(255,255,255,.08); }
.logo-mark { font-size: 24px; }
.menu { flex: 1; padding: 12px 10px; overflow-y: auto; scrollbar-width: none; }
.menu::-webkit-scrollbar { display: none; }
.menu-item {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 8px;
  color: #cbd5e1; font-size: 14px; margin-bottom: 2px; transition: background .15s;
}
.menu-item:hover { background: rgba(255,255,255,.06); color: #fff; }
.menu-item.active { background: var(--green); color: #fff; font-weight: 600; }
.mi-icon { font-size: 16px; width: 20px; text-align: center; }
.sidebar-foot { padding: 14px 18px; font-size: 12px; color: #64748b; border-top: 1px solid rgba(255,255,255,.08); line-height: 1.8; }
.icp-link { color: #64748b; text-decoration: none; font-size: 11px; }
.icp-link:hover { color: #94a3b8; text-decoration: underline; }
.login-icp { margin-top: 16px; text-align: center; }
.login-icp a { color: #94a3b8; text-decoration: none; font-size: 12px; }
.login-icp a:hover { text-decoration: underline; }
.aging-total td { font-weight: 600; background: #f1f5f9; border-top: 2px solid #cbd5e1; }
.stmt-card { background: #fff; border: 1px solid var(--border, #e2e8f0); border-radius: 10px; padding: 18px 20px; margin: 4px 0 16px; }
.stmt-head { display: flex; justify-content: space-between; align-items: baseline; flex-wrap: wrap; gap: 6px; border-bottom: 2px solid #0f766e; padding-bottom: 10px; margin-bottom: 12px; }
.stmt-head b { font-size: 16px; }
.stmt-head span { color: #475569; font-size: 13px; }
.stmt-sum { display: flex; flex-wrap: wrap; gap: 18px; background: #f0fdfa; border: 1px solid #99f6e4; border-radius: 8px; padding: 10px 14px; margin-bottom: 12px; font-size: 13px; color: #334155; }
.stmt-sum b { margin-left: 4px; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
#topbar {
  height: 58px; background: var(--panel); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; padding: 0 20px;
  position: sticky; top: 0; z-index: 50;
}
.tb-title { font-size: 17px; font-weight: 700; }
.tb-right { display: flex; align-items: center; gap: 14px; }
.tb-user { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.tb-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--green-light); color: var(--green-dark); display: flex; align-items: center; justify-content: center; font-weight: 700; }
.tb-role { color: var(--muted); font-size: 12px; background: #f1f5f9; padding: 2px 8px; border-radius: 10px; }

#content { padding: 22px; flex: 1; }

/* ===== 连接状态徽标 ===== */
.conn-badge { font-size: 12px; padding: 3px 10px; border-radius: 12px; cursor: default; }
.conn-ok { background: var(--green-light); color: var(--green-dark); }
.conn-local { background: #e0f2fe; color: #0369a1; }
.conn-down { background: #fee2e2; color: #b91c1c; cursor: pointer; }
.conn-bad { background: #fee2e2; color: #b91c1c; cursor: pointer; }
.conn-connecting { background: #fef3c7; color: #b45309; }

/* ===== 更新横幅 ===== */
#update-banner {
  position: fixed; top: 0; left: 0; right: 0; z-index: 999;
  background: #fef3c7; color: #92400e; text-align: center; padding: 8px;
  font-size: 13px; box-shadow: var(--shadow);
}
#update-banner a { font-weight: 700; text-decoration: underline; }

/* ===== 按钮 ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px; border: 1px solid transparent;
  border-radius: 8px; padding: 8px 16px; font-size: 14px; cursor: pointer; font-weight: 500;
  transition: all .15s; background: #fff; color: var(--text);
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
.btn-ghost { background: #fff; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: #f8fafc; }
.btn-sm { padding: 5px 12px; font-size: 13px; }
.btn-refresh { padding: 5px 10px; line-height: 1; }
.btn-refresh .icon-refresh { display: block; }
.btn-refresh:hover .icon-refresh { color: var(--green); }
.btn-refresh.spinning .icon-refresh { animation: spin .6s linear; }
@keyframes spin { to { transform: rotate(360deg); } }
.btn-block { width: 100%; justify-content: center; }
.btn-icon { border: none; background: transparent; color: var(--muted); font-size: 18px; cursor: pointer; border-radius: 6px; width: 28px; height: 28px; line-height: 1; }
.btn-icon:hover { background: #fee2e2; color: var(--danger); }
.btn-link { border: none; background: transparent; color: var(--green); cursor: pointer; font-size: 13px; padding: 0 6px; }
.btn-link:hover { text-decoration: underline; }
.btn-link.btn-del { color: var(--danger); }

/* ===== 列表页 ===== */
.list-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }
.list-head h2 { margin: 0; font-size: 18px; }
.count { font-size: 13px; color: var(--muted); font-weight: 400; margin-left: 8px; }
.list-tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.search { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 14px; min-width: 200px; outline: none; }
.search:focus { border-color: var(--green); }
.select-inline { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 14px; background: #fff; }

/* ===== 表头筛选按钮 ===== */
.th-filterable { cursor: pointer; }
.th-filterable .th-label { display: inline-block; }
.th-filterable:hover .th-label { color: var(--green); }
.th-filter-btn {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; background: transparent; cursor: pointer; padding: 0 3px;
  margin-left: 2px; vertical-align: middle; position: relative; outline: none;
}
.th-filter-btn .fp-arrow {
  display: inline-block; width: 0; height: 0;
  border-left: 4px solid transparent; border-right: 4px solid transparent;
  border-top: 5px solid #94a3b8; transition: border-top-color .15s;
}
.th-filter-btn:hover .fp-arrow { border-top-color: var(--green); }
.th-filter-btn.open .fp-arrow,
.th-filter-btn.active .fp-arrow { border-top-color: var(--green); }
.th-filter-btn.active::after {
  content: ''; position: absolute; top: 0; right: 0;
  width: 6px; height: 6px; border-radius: 50%; background: var(--green);
}

/* ===== 筛选下拉面板 ===== */
.filter-panel {
  position: fixed; z-index: 1100; min-width: 200px; max-width: 280px;
  background: #fff; border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .14); padding: 10px; box-sizing: border-box;
}
.fp-head { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.fp-search { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 6px 9px; font-size: 13px; margin-bottom: 6px; outline: none; box-sizing: border-box; }
.fp-search:focus { border-color: var(--green); }
.fp-options { max-height: 230px; overflow-y: auto; }
.fp-option { padding: 7px 9px; border-radius: 6px; font-size: 13px; cursor: pointer; color: var(--text); }
.fp-option:hover { background: #f1f5f9; }
.fp-option.selected { background: var(--green-light); color: var(--green-dark); }
.fp-date { display: flex; flex-direction: column; gap: 8px; }
.fp-date label { font-size: 12px; color: var(--muted); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.fp-date-input { border: 1px solid var(--border); border-radius: 6px; padding: 5px 7px; font-size: 13px; outline: none; }
.fp-date-input:focus { border-color: var(--green); }
.fp-actions { display: flex; gap: 8px; margin-top: 10px; justify-content: flex-end; }

.table-wrap { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.data-table th, .data-table td { padding: 11px 14px; text-align: left; white-space: nowrap; }
.data-table thead th { background: #f8fafc; color: var(--muted); font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--border); }
.data-table tbody tr { border-bottom: 1px solid #f1f5f9; }
.data-table tbody tr:hover { background: #f8fafc; }
.data-table td.num { text-align: right; font-variant-numeric: tabular-nums; }
.data-table .empty { text-align: center; color: var(--muted); padding: 32px; }
.td-act { text-align: right; }
.th-act { text-align: right; }
.text-danger { color: var(--danger); }

/* ===== 状态徽标 ===== */
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge-danger { background: #fee2e2; color: #b91c1c; }
.badge-warn { background: #fef3c7; color: #b45309; }
.badge-ok { background: var(--green-light); color: var(--green-dark); }

/* ===== 页签 ===== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; flex-wrap: wrap; }
.tab { padding: 9px 16px; color: var(--muted); font-size: 14px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--green); border-bottom-color: var(--green); font-weight: 600; }
.tab-body { min-height: 200px; }

/* ===== 工作台 ===== */
.dash-hello { font-size: 16px; margin-bottom: 18px; }
.dash-role { color: var(--muted); font-size: 13px; margin-left: 6px; }
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat-card { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.stat-val { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.stat-label { color: var(--muted); font-size: 13px; }
.stat-money .stat-val { color: var(--green-dark); }
.dash-cols { display: grid; grid-template-columns: 1.5fr 1fr; gap: 18px; }
.dash-panel { background: var(--panel); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; }
.dash-panel h3 { margin: 0 0 14px; font-size: 15px; }
.todo-list { list-style: none; margin: 0; padding: 0; }
.todo-list li { margin-bottom: 4px; }
.todo-list a { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; color: var(--text); }
.todo-list a:hover { background: #f8fafc; }
.todo-tag { flex-shrink: 0; font-size: 11px; padding: 2px 8px; border-radius: 10px; font-weight: 600; }
.tag-p0 { background: #7f1d1d; color: #fff; }
.tag-p1 { background: #fee2e2; color: #b91c1c; }
.tag-p2 { background: #fef3c7; color: #b45309; }
.tag-p3 { background: #e0f2fe; color: #0369a1; }
.tag-p4 { background: #f3e8ff; color: #7c3aed; }
.todo-title { font-weight: 600; flex-shrink: 0; }
.todo-desc { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.qa-btn { border: 1px solid var(--border); border-radius: 8px; padding: 12px; text-align: center; color: var(--text); background: #fff; }
.qa-btn:hover { border-color: var(--green); color: var(--green); }

/* ===== 条形图 ===== */
.bars { display: flex; flex-direction: column; gap: 8px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 90px; flex-shrink: 0; font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { flex: 1; height: 16px; background: #f1f5f9; border-radius: 8px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--green); border-radius: 8px; min-width: 2px; }
.bar-val { width: 70px; text-align: right; font-size: 12px; font-variant-numeric: tabular-nums; }

/* ===== 权限矩阵 ===== */
.hint { color: var(--muted); font-size: 13px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.perm-table td { text-align: center; }
.perm-mod { text-align: left !important; font-weight: 600; }
.perm-cell input { width: 16px; height: 16px; cursor: pointer; }
.matrix-foot { margin-top: 14px; }

/* ===== 表单 / 弹窗 ===== */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 23, 42, .45); z-index: 1000;
  display: flex; align-items: center; justify-content: center; padding: 20px;
}
.modal { background: #fff; border-radius: 14px; width: 100%; max-width: 860px; max-height: 90vh; display: flex; flex-direction: column; box-shadow: 0 20px 50px rgba(0,0,0,.2); }
.modal.modal-sm { max-width: 440px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 22px; border-bottom: 1px solid var(--border); }
.modal-title { font-size: 16px; font-weight: 700; }
.modal-close { border: none; background: transparent; font-size: 24px; color: var(--muted); cursor: pointer; line-height: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; }
.modal-foot { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 10px; }

/* 非阻塞提示 toast（替代原生 alert） */
.toast {
  position: fixed; top: 18px; left: 50%; transform: translateX(-50%);
  z-index: 3000; max-width: 80vw;
  background: #0f172a; color: #fff;
  padding: 11px 18px; border-radius: 10px; font-size: 14px; line-height: 1.6;
  box-shadow: 0 8px 30px rgba(0, 0, 0, .25); cursor: pointer;
  animation: toast-in .18s ease-out;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } to { opacity: 1; transform: translate(-50%, 0); } }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 18px; }
.form-item { display: flex; flex-direction: column; gap: 5px; }
.form-item.full { grid-column: 1 / -1; }
.form-label { font-size: 13px; color: var(--muted); font-weight: 600; }
.req { color: var(--danger); }
.form-item input, .form-item select, .form-item textarea {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 12px; font-size: 14px; outline: none; background: #fff; font-family: inherit;
}
.form-item input:focus, .form-item select:focus, .form-item textarea:focus { border-color: var(--green); }
.form-item input:disabled, .form-item select:disabled, .form-item textarea:disabled { background: #f8fafc; color: var(--muted); }

/* 密码字段：眼睛图标切换 明文/掩码 */
.pwd-wrap { position: relative; display: block; }
.pwd-wrap input { width: 100%; padding-right: 40px; box-sizing: border-box; }
.pwd-toggle { position: absolute; right: 4px; top: 50%; transform: translateY(-50%); border: none; background: transparent; color: var(--muted); cursor: pointer; padding: 5px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.pwd-toggle:hover { color: #111827; background: #f1f5f9; }
.pwd-toggle.is-on { color: var(--green); }

/* 文件上传（盖章合同） */
.form-item input[type="file"] { padding: 7px; font-size: 13px; }
.file-preview { margin-top: 2px; }
.file-preview img { max-width: 160px; max-height: 120px; border: 1px solid var(--border); border-radius: 8px; display: block; object-fit: cover; }
.file-hint { font-size: 11px; color: var(--muted); }

/* 开关 */
.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch span { position: absolute; inset: 0; background: #cbd5e1; border-radius: 24px; transition: .2s; cursor: pointer; }
.switch span:before { content: ""; position: absolute; left: 3px; top: 3px; width: 18px; height: 18px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--green); }
.switch input:checked + span:before { transform: translateX(20px); }

/* 明细编辑器 */
.items-section { margin-top: 16px; }
.items-table { width: 100%; border-collapse: collapse; font-size: 13px; margin-bottom: 8px; }
.items-table th { text-align: left; color: var(--muted); font-size: 12px; font-weight: 600; padding: 4px 4px 6px; border-bottom: 1px solid var(--border); }
.items-table td { padding: 4px; }
.items-table input, .items-table select { width: 100%; border: 1px solid var(--border); border-radius: 6px; padding: 7px 8px; font-size: 13px; outline: none; font-family: inherit; background: #fff; }
.items-table input:focus, .items-table select:focus { border-color: var(--green); }
.items-table td:first-child { min-width: 140px; }
.items-table td:nth-child(2) { width: 70px; }
.items-table .item-unit { display: block; text-align: center; color: #64748b; padding: 7px 2px; }
.items-table .item-code { display: block; text-align: center; color: #475569; font-variant-numeric: tabular-nums; padding: 7px 2px; white-space: nowrap; }
.items-table .item-readonly { display: block; color: #0f766e; font-weight: 600; padding: 7px 2px; }
.items-table .item-readonly.is-placeholder { color: #94a3b8; font-weight: 400; }

/* ===== 登录页 ===== */
.login-wrap { width: 100%; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #16a34a 0%, #15803d 40%, #0f172a 100%); padding: 20px; }
.login-card { background: #fff; border-radius: 16px; padding: 36px; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); text-align: center; }
.login-logo { font-size: 48px; }
.login-card h1 { margin: 12px 0 4px; font-size: 24px; }
.login-sub { color: var(--muted); margin: 0 0 22px; font-size: 14px; }
.login-form { display: flex; flex-direction: column; gap: 14px; text-align: left; }
.login-form label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); font-weight: 600; }
.login-form input { border: 1px solid var(--border); border-radius: 8px; padding: 11px 13px; font-size: 15px; outline: none; }
.login-form input:focus { border-color: var(--green); }
.login-form label.login-remember { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; font-size: 13px; cursor: pointer; }
.login-form label.login-remember input[type="checkbox"] { width: 16px; height: 16px; padding: 0; margin: 0; flex: 0 0 auto; }
.login-demo { margin-top: 18px; font-size: 12px; color: var(--muted); line-height: 1.8; }
.demo-acct { margin: 0 2px; }
.login-alert { text-align: left; font-size: 12px; padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; line-height: 1.6; }
.alert-danger { background: #fee2e2; color: #b91c1c; }
.alert-info { background: #e0f2fe; color: #0369a1; }

/* ===== 响应式 ===== */
@media (max-width: 860px) {
  #app { flex-direction: column; }
  #sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .logo { border-bottom: none; padding: 12px 16px; }
  .menu { display: flex; flex-direction: row; overflow-x: auto; padding: 8px; }
  .menu-item { white-space: nowrap; }
  .sidebar-foot { display: none; }
  #topbar { height: auto; min-height: 54px; flex-wrap: wrap; padding: 10px 16px; gap: 8px; }
  .tb-role { display: none; }
  #content { padding: 14px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .dash-cols { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .modal { max-width: 100%; }
  .list-head h2 { font-size: 16px; }
}
