:root {
  --primary: #2e7d6b;
  --primary-dark: #1f5a4d;
  --primary-light: #e8f5f1;
  --accent: #d97706;
  --danger: #dc2626;
  --success: #16a34a;
  --warn: #f59e0b;
  --bg: #f5f7fa;
  --card: #ffffff;
  --border: #e5e7eb;
  --text: #1f2937;
  --text-light: #6b7280;
  --shadow: 0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 10px 30px rgba(0,0,0,.1);
  --radius: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: -apple-system, "Microsoft YaHei", "Segoe UI", sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }

.layout { display: flex; min-height: 100vh; }

/* 侧边栏 */
.sidebar { width: 220px; background: var(--primary-dark); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh; }
.brand { padding: 20px 18px; display: flex; align-items: center; gap: 12px; border-bottom: 1px solid rgba(255,255,255,.1); }
.brand-logo { width: 40px; height: 40px; border-radius: 8px; background: var(--accent); display: flex; align-items: center; justify-content: center; font-size: 22px; font-weight: 700; }
.brand-name { font-size: 16px; font-weight: 600; }
.brand-sub { font-size: 12px; opacity: .7; }
.nav { padding: 12px 0; flex: 1; }
.nav-item { display: flex; align-items: center; gap: 10px; padding: 11px 20px; color: rgba(255,255,255,.85); text-decoration: none; transition: all .15s; border-left: 3px solid transparent; }
.nav-item:hover { background: rgba(255,255,255,.08); color: #fff; }
.nav-item.active { background: rgba(255,255,255,.12); color: #fff; border-left-color: var(--accent); }
.nav-icon { width: 20px; flex-shrink: 0; text-align: center; font-size: 15px; line-height: 1; }
.nav-text { flex: 1; white-space: nowrap; }
.sidebar-footer { padding: 14px 20px; font-size: 11px; opacity: .5; }

/* 内容区 */
.content { flex: 1; padding: 24px 28px; height: 100vh; overflow-y: auto; overflow-x: auto; }
.page-title { font-size: 20px; font-weight: 600; margin-bottom: 4px; }
.page-desc { color: var(--text-light); margin-bottom: 20px; font-size: 13px; }

/* 卡片 */
.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 16px; }
.card-title { font-size: 14px; font-weight: 600; margin-bottom: 12px; color: var(--text); }

/* 统计卡片网格 */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; border-left: 4px solid var(--primary); }
.stat-card.income { border-left-color: var(--success); }
.stat-card.expense { border-left-color: var(--danger); }
.stat-card.balance { border-left-color: var(--accent); }
.stat-card.warn { border-left-color: var(--warn); }
.stat-label { font-size: 12px; color: var(--text-light); margin-bottom: 6px; }
.stat-value { font-size: 24px; font-weight: 700; }
.stat-value.income { color: var(--success); }
.stat-value.expense { color: var(--danger); }
.stat-value.balance { color: var(--accent); }
.stat-sub { font-size: 11px; color: var(--text-light); margin-top: 4px; }

/* 表格 */
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; padding: 10px 12px; background: #f9fafb; color: var(--text-light); font-weight: 600; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th.text-right { text-align: right; }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.table tr:hover td { background: #f9fafb; }
.table-wrap { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); overflow: auto; margin-bottom: 16px; }

/* 按钮 */
.btn { display: inline-block; padding: 7px 14px; border: none; border-radius: 6px; cursor: pointer; font-size: 13px; background: var(--primary); color: #fff; transition: all .15s; }
.btn:hover { background: var(--primary-dark); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b91c1c; }
.btn-ghost { background: #f3f4f6; color: var(--text); }
.btn-ghost:hover { background: #e5e7eb; }
.btn-warn { background: var(--warn); }
.btn-warn:hover { background: #d97706; }

/* 表单 */
.form-row { display: flex; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.form-item { flex: 1; min-width: 180px; }
.form-item label { display: block; font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.form-item label .req { color: var(--danger); }
input, select, textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: 6px; font-size: 13px; font-family: inherit; background: #fff; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-light); }

/* 筛选栏 */
.filter-bar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; }
.filter-bar select, .filter-bar input { width: auto; min-width: 130px; }
.filter-checks { display: flex; gap: 14px; align-items: center; }
.filter-checks label { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-light); cursor: pointer; white-space: nowrap; }
.filter-checks input { width: auto; min-width: 0; }

/* 模态框 */
.modal-mask { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: center; justify-content: center; z-index: 100; }
.modal { background: #fff; border-radius: 10px; box-shadow: var(--shadow-lg); width: 560px; max-width: 92vw; max-height: 88vh; overflow: auto; }
.modal-header { padding: 16px 20px; border-bottom: 1px solid var(--border); display: flex; justify-content: space-between; align-items: center; }
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { cursor: pointer; font-size: 20px; color: var(--text-light); background: none; border: none; }
.modal-body { padding: 20px; }
.modal-footer { padding: 14px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* 提醒红牌 */
.remind-card { background: #fef3c7; border: 1px solid #fcd34d; border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; display: flex; justify-content: space-between; align-items: center; }
.remind-card.urgent { background: #fee2e2; border-color: #fca5a5; }
.remind-card .info { flex: 1; }
.remind-card .name { font-weight: 600; }
.remind-card .meta { font-size: 12px; color: var(--text-light); margin-top: 2px; }
.remind-card .days { font-size: 13px; font-weight: 700; color: var(--danger); margin-left: 10px; }

/* 标签 */
.tag { display: inline-block; padding: 2px 8px; border-radius: 4px; font-size: 11px; font-weight: 600; }
.tag-rent { background: #dbeafe; color: #1e40af; }
.tag-mgmt { background: #ede9fe; color: #5b21b6; }
.tag-elec_recharge { background: #fef3c7; color: #92400e; }
.tag-capacity_fee { background: #e0e7ff; color: #3730a3; }
.tag-water { background: #cffafe; color: #0e7490; }
.tag-grid_power { background: #fee2e2; color: #991b1b; }
.tag-sewage { background: #d1fae5; color: #065f46; }
.tag-garbage { background: #fce7f3; color: #9d174d; }
.tag-other { background: #f3f4f6; color: #374151; }
.tag-active { background: #d1fae5; color: #065f46; }
.tag-inactive { background: #fee2e2; color: #991b1b; }

/* 停租行灰度（状态列、操作列除外） */
.table tr.row-inactive td { opacity: 0.45; }
.table tr.row-inactive td:nth-child(10),
.table tr.row-inactive td:nth-child(11) { opacity: 1; }

/* 空状态 */
.empty { text-align: center; padding: 40px; color: var(--text-light); }

/* 明细弹窗表格不换行（备注列除外） */
.modal .table td { white-space: nowrap; }
.modal .table td:last-child { white-space: normal; }

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

/* 工具类 */
.row { display: flex; gap: 12px; align-items: center; }
.flex-1 { flex: 1; }
.mt-12 { margin-top: 12px; }
.mb-12 { margin-bottom: 12px; }
.text-right { text-align: right; }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.text-warn { color: var(--warn); }
.fw-600 { font-weight: 600; }
.nowrap { white-space: nowrap; }

/* ============ 系统设置 tab ============ */
.settings-tabs { display: flex; gap: 4px; margin-bottom: 16px; flex-wrap: wrap; border-bottom: 2px solid var(--border); padding-bottom: 0; }
.settings-tab { padding: 8px 16px; border: none; background: none; cursor: pointer; font-size: 13px; color: var(--text-light); border-bottom: 2px solid transparent; margin-bottom: -2px; transition: all .15s; }
.settings-tab:hover { color: var(--text); }
.settings-tab.active { color: var(--primary); border-bottom-color: var(--primary); font-weight: 600; }

/* ============ 权限控制（无权限时隐藏，按细粒度） ============ */
body:not(.perm-payments_add) .btn-payments-add { display: none !important; }
body:not(.perm-payments_delete) .btn-payments-delete { display: none !important; }
body:not(.perm-expenses_add) .btn-expenses-add { display: none !important; }
body:not(.perm-expenses_delete) .btn-expenses-delete { display: none !important; }
body:not(.perm-pending_add) .btn-pending-add { display: none !important; }
body:not(.perm-pending_pay) .btn-pending-pay { display: none !important; }
body:not(.perm-pending_delete) .btn-pending-delete { display: none !important; }
body:not(.perm-elec_add) .btn-elec-add { display: none !important; }
body:not(.perm-elec_delete) .btn-elec-delete { display: none !important; }
body:not(.perm-tenants_edit) .btn-tenants-edit { display: none !important; }
body:not(.perm-tenants_delete) .btn-tenants-delete { display: none !important; }
body:not(.perm-settings_backup) #tab-backup { display: none !important; }
body:not(.perm-settings_backup) #backup-btn { display: none !important; }

/* ============ 登录页 ============ */
.login-wrap { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: linear-gradient(135deg, #1f5a4d 0%, #2e7d6b 100%); z-index: 1; }
.login-card { background: rgba(255, 255, 255, 0.88); backdrop-filter: blur(8px); border-radius: 12px; padding: 40px 36px; width: 360px; max-width: 92vw; box-shadow: 0 20px 60px rgba(0,0,0,.25); text-align: center; }
.login-logo { width: 66px; height: 66px; border-radius: 12px; background: var(--accent); color: #fff; display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 700; margin: 0 auto 16px; }
.login-title { font-size: 18px; font-weight: 600; margin-bottom: 4px; }
.login-sub { color: var(--text-light); font-size: 13px; margin-bottom: 24px; }
.login-form { text-align: left; }
.login-form .form-item { margin-bottom: 14px; }
.login-form label { display: block; font-size: 12px; color: var(--text-light); margin-bottom: 4px; }
.login-btn { width: 100%; padding: 10px; font-size: 14px; margin-top: 6px; }
.login-tip { margin-top: 18px; font-size: 11px; color: var(--text-light); }

/* ============ 移动端响应式 ============ */
@media (max-width: 768px) {
   .layout { flex-direction: column; }
   .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-shrink: 0;
  }
  .sidebar.collapsed { height: auto; }
  .sidebar.collapsed .nav { display: none; }
  .sidebar.collapsed .sidebar-footer { display: none; }
  .nav { padding: 0; }
  .nav-item { padding: 9px 20px; }
  .content { padding: 14px 14px; height: auto; min-height: calc(100vh - 60px); }
  .page-title { font-size: 18px; }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .stat-card { padding: 12px; }
  .stat-value { font-size: 18px; }
  .filter-bar { gap: 8px; }
  .filter-bar select, .filter-bar input { min-width: 0; width: 100%; }
  .filter-checks { width: 100%; justify-content: flex-start; }
  .table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { min-width: 600px; font-size: 12px; }
  .table th, .table td { padding: 8px 8px; }
  .modal { width: 96vw; max-height: 90vh; }
  .modal-body { padding: 14px; }
  .form-row { flex-direction: column; gap: 8px; }
  .form-item { min-width: 0; }
  .chart { height: 240px; }
  .card { padding: 14px; }
}

@media (max-width: 480px) {
  .stat-grid { grid-template-columns: 1fr; }
  .brand-name { font-size: 14px; }
  .brand-sub { font-size: 11px; }
}
